|
|
1.1 root 1: /* The Plum Hall Validation Suite for C
2: * Unpublished copyright (c) 1986-1991, Chiron Systems Inc and Plum Hall Inc.
3: * VERSION: 4
4: * DATE: 1993-01-01
5: * The "ANSI" mode of this suite corresponds to official ANSI C, X3.159-1989.
6: * As per your license agreement, your distribution is not to be moved or copied outside the Designated Site
7: * without specific permission from Plum Hall Inc.
8: */
9:
10: #define LIB_TEST 1
11: #include "defs.h"
12: #if !ANSI && !V7
13: #define SKIP45 /* prior to V7, too little commonality in math to be tested */
14: #endif
15:
16: #include "flags.h"
17: #ifndef SKIP45
18: /*
19: * 4.5 - Mathematics
20: */
21: #include <math.h>
22: #if !ANSI
23: #include <errno.h>
24: extern int errno;
25: #ifndef HUGE_VAL
26: #define HUGE_VAL HUGE /* the most common other name */
27: #endif /* of HUGE_VAL */
28: #else /* if ANSI */
29: #if ANSI8703
30: #include <errno.h>
31: #else /* ANSI, but not 8703 */
32: #include <stddef.h>
33: #endif /* ANSI8703 */
34: #endif /* !ANSI */
35: static void d4_5_2();
36: static void d4_5_3();
37: static void d4_5_4();
38: static void d4_5_5();
39: static void d4_5_6();
40: /* 4.5 - Mathmatics <math.h>
41: * This version is not intended to verify the "correctness" of the
42: * results of the math library, but rather to verify the existence
43: * of the functions and some domain/range properties.
44: */
45: void d4_5()
46: {
47: Filename = "d45.c";
48: checkthat(__LINE__, EDOM != ERANGE);
49: checkthat(__LINE__, EDOM != 0);
50: checkthat(__LINE__, ERANGE != 0);
51: checkthat(__LINE__, HUGE_VAL > 0);
52: d4_5_2();
53: d4_5_3();
54: d4_5_4();
55: d4_5_5();
56: d4_5_6();
57: }
58:
59: /*
60: * 4.5.2 - Trignometric functions
61: */
62: static void d4_5_2()
63: {
64: #ifndef SKIP452
65: double pi = acos(-1.);
66: double dummy;
67:
68: /* 4.5.2.1 acos
69: * has domain on [-1,1]
70: */
71: dequals(__LINE__, acos(1.), 0.0);
72: dequals(__LINE__, acos(0.), pi/2);
73: dequals(__LINE__, acos(-1.), pi);
74: dequals(__LINE__, acos(cos(pi/4)), pi/4);
75:
76: /* 4.5.2.2 asin
77: * has domain on [-1,1]
78: */
79: dequals(__LINE__, asin(1.), pi/2);
80: dequals(__LINE__, asin(0.), 0.0);
81: dequals(__LINE__, asin(-1.), -pi/2);
82: dequals(__LINE__, asin(cos(pi/4)), pi/4);
83:
84: /* 4.5.2.3 atan
85: * has domain (-HUGE_VAL, HUGE_VAL)
86: */
87: dequals(__LINE__, atan(0.0), 0.0);
88: dequals(__LINE__, atan(1.0), pi/4);
89: dequals(__LINE__, atan(tan(pi/7)), pi/7);
90:
91:
92: /* 4.5.2.4 atan2
93: * figures out the correct quadrant
94: */
95: dequals(__LINE__, atan2(sin(pi/4), cos(pi/4)), pi/4);
96: dequals(__LINE__, atan2(sin(3*pi/4), cos(3*pi/4)), 3*pi/4);
97: dequals(__LINE__, atan2(sin(-pi/4), cos(-pi/4)), -pi/4);
98: dequals(__LINE__, atan2(sin(-3*pi/4), cos(-3*pi/4)), -3*pi/4);
99: errno = 0;
100: atan2(0.0, 0.0);
101: iequals( - __LINE__, errno, EDOM);
102:
103: /* 4.5.2.5 cos
104: * works in radians
105: */
106: dequals(__LINE__, cos(0.0), 1.0);
107: dequals(__LINE__, cos(pi/2), 0.0);
108: dequals(__LINE__, cos(pi), -1.0);
109: dequals(__LINE__, cos(3*pi/2), 0.0);
110: dequals(__LINE__, cos(pi/4), cos(-pi/4));
111: dequals(__LINE__, cos(pi/4), sin(pi/4));
112:
113: /* 4.5.2.6 sin
114: * works in radians
115: */
116: dequals(__LINE__, sin(0.0), 0.0);
117: dequals(__LINE__, sin(pi/2), 1.0);
118: dequals(__LINE__, sin(pi), 0.0);
119: dequals(__LINE__, sin(3*pi/2), -1.0);
120: dequals(__LINE__, sin(pi/2), -sin(-pi/2));
121:
122: /* 4.5.2.7 tan
123: * also works on radians
124: */
125: dequals(__LINE__, tan(0.0), 0.0);
126: dequals(__LINE__, tan(pi/4), 1.0);
127: dequals(__LINE__, tan(-pi/4), -1.0);
128: #endif /* SKIP452 */
129: }
130:
131: /*
132: * 4.5.3 - Hyperbolic functions
133: */
134: static void d4_5_3()
135: {
136: #ifndef SKIP453
137: double pi = acos(-1.);
138:
139: /* 4.5.3.1 cosh
140: * range error returns HUGE_VAL and sets errno
141: */
142: errno = 0;
143: dequals(__LINE__, cosh(HUGE_VAL), HUGE_VAL);
144: iequals( - __LINE__, errno, ERANGE);
145: dequals(__LINE__, cosh(1.234), cosh(-1.234));
146: errno = 0;
147:
148: /* 4.5.3.2 sinh
149: */
150: dequals(__LINE__, sinh(HUGE_VAL), HUGE_VAL);
151: iequals( - __LINE__, errno, ERANGE);
152: dequals(__LINE__, sinh(1.234), -sinh(-1.234));
153:
154: /* 4.5.3.3 tanh
155: */
156: dequals(__LINE__, tanh(1.234), sinh(1.234)/cosh(1.234));
157: dequals(__LINE__, tanh(0.0), 0.0);
158: dequals(__LINE__, tanh(1.234), -tanh(-1.234));
159: #endif /* SKIP453 */
160: }
161:
162: /*
163: * 4.5.4 - Exponential and logrithmic functions
164: */
165: static void d4_5_4()
166: {
167: #ifndef SKIP454
168: int i;
169: double dummy;
170:
171: /* 4.5.4.1 exp
172: */
173: dequals(__LINE__, exp(HUGE_VAL), HUGE_VAL);
174: iequals( - __LINE__, errno, ERANGE);
175: dequals(__LINE__, exp(0.0), 1.0);
176: dequals(__LINE__, exp(-1.1), 1.0/exp(1.1));
177:
178: /* 4.5.4.2 frexp
179: */
180: dequals(__LINE__, frexp(1.234, &i), .617);
181: iequals(__LINE__, i, 1);
182: dequals(__LINE__, frexp(12.34, &i), .77125);
183: iequals(__LINE__, i, 4);
184: dequals(__LINE__, frexp(0.0, &i), 0.0);
185: iequals(__LINE__, i, 0);
186:
187: /* 4.5.4.3 ldexp
188: */
189: dequals(__LINE__, ldexp(3.0, 2), 12.0);
190: errno = 0;
191: dequals(__LINE__, ldexp(1e37, 32767), HUGE_VAL);
192: iequals( - __LINE__, errno, ERANGE);
193:
194: /* 4.5.4.4 log
195: */
196: errno = 0;
197: dummy = log(-1.0);
198: iequals(__LINE__, errno, EDOM);
199: errno = 0;
200: iequals( - __LINE__, errno, ERANGE);
201: dequals(__LINE__, exp(log(1.234)), 1.234);
202:
203: /* 4.5.4.5 log10
204: */
205: errno = 0;
206: dummy = log10(-1.0);
207: iequals(__LINE__, errno, EDOM);
208: errno = 0;
209: iequals( - __LINE__, errno, ERANGE);
210: dequals(__LINE__, log10(1.0), 0.0);
211: dequals(__LINE__, log10(1.e10), 10.0);
212:
213: /* 4.5.4.6 modf
214: */
215: dequals(__LINE__, modf(12.345, &dummy), .345);
216: dequals(__LINE__, dummy, 12.);
217: dequals(__LINE__, modf(0.0, &dummy), 0.0);
218: dequals(__LINE__, dummy, 0.0);
219: #endif /* SKIP454 */
220: }
221:
222: /*
223: * 4.5.5 - Power functions
224: */
225: static void d4_5_5()
226: {
227: #ifndef SKIP455
228: double dummy;
229:
230: /* 4.5.5.1 pow
231: */
232: errno = 0;
233: dummy = pow(0.0, 0.0);
234: iequals( - __LINE__, errno, EDOM);
235: errno = 0;
236: dummy = pow(0.0, -1.0);
237: iequals( - __LINE__, errno, EDOM);
238: errno = 0;
239: dummy = pow(-4.3, 1.1);
240: iequals(__LINE__, errno, EDOM);
241: dequals(__LINE__, log10(pow(10.0, 1.234)), 1.234);
242: dequals(__LINE__, pow(-3.0, 3.0), -27.0);
243:
244: /* range errors */
245: errno = 0;
246: dequals(__LINE__, pow(10.0, HUGE_VAL), HUGE_VAL);
247: iequals( - __LINE__, errno, ERANGE);
248: errno = 0;
249: /* underflow */
250: dequals(__LINE__, pow(10.0, -HUGE_VAL), 0.0);
251: iequals( - __LINE__, errno, ERANGE);
252:
253: /* 4.5.5.2 sqrt
254: */
255: dequals(__LINE__, pow(sqrt(1.234), 2.0), 1.234);
256: #endif /* SKIP455 */
257: }
258:
259: /*
260: * 4.5.6 - Nearest integer, absolute value, and remainder functions
261: */
262: static void d4_5_6()
263: {
264: #ifndef SKIP456
265: /* 4.5.6.1 ceil
266: */
267: dequals(__LINE__, ceil(0.0), 0.0);
268: dequals(__LINE__, ceil(12.345), 13.0);
269: dequals(__LINE__, ceil(-12.345), -12.0);
270:
271: /* 4.5.6.2 fabs
272: */
273: dequals(__LINE__, fabs(12.345), 12.345);
274: dequals(__LINE__, fabs(-12.345), 12.345);
275:
276: /* 4.5.6.3 floor
277: */
278: dequals(__LINE__, floor(0.0), 0.0);
279: dequals(__LINE__, floor(12.345), 12.0);
280: dequals(__LINE__, floor(-12.345), -13.0);
281: #if ANSI
282: /* 4.5.6.4 fmod
283: */
284: dequals(__LINE__, fmod(13.1, 5.0), 3.1);
285: dequals(__LINE__, fmod(-13.1, 5.0), -3.1);
286: dequals(__LINE__, fmod(13.1, -5.0), 3.1);
287: dequals(__LINE__, fmod(-13.1, -5.0), -3.1);
288: #if ANSI8612
289: dequals(- __LINE__, fmod(1., 0.), 0.); /* DEC86 */
290: checkthat(__LINE__, fmod(1E38, 1E-38) <= 1E-38); /* DEC86 */
291: #endif
292: #endif
293: #endif /* SKIP456 */
294: }
295:
296: #else /* if SKIP45 */
297: void d4_5() { pr_skip("d4_5: SKIPPED ENTIRELY\n"); }
298: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.