2 /* Program to check that the FP stuff underlying these common FP
3 functions isn't too badly broken. Carefully kludged to print the
4 same answers on different platforms (even when run natively). */
15 const double tinyD
= 0.0000000001;
16 const double tinyF
= 0.0001;
18 /* -------------------- any arg -------------------- */
21 for (i
= 0; i
< 41; i
++) {
22 printf("floorD(%+20.13e) = %+20.13e\n", d
, floor(d
));
26 for (i
= 0; i
< 41; i
++) {
27 printf("floorF(%+20.4e) = %+20.4e\n", (double)f
, (double)floorf(f
));
33 for (i
= 0; i
< 41; i
++) {
34 printf(" ceilD(%+20.13e) = %+20.13e\n", d
, ceil(d
));
38 for (i
= 0; i
< 41; i
++) {
39 printf(" ceilF(%+20.4e) = %+20.4e\n", (double)f
, (double)ceilf(f
));
45 for (i
= 0; i
< 41; i
++) {
46 printf(" sinD(%+20.13e) = %+20.13e\n", d
, sin(d
));
50 for (i
= 0; i
< 41; i
++) {
51 printf(" sinF(%+20.4e) = %+20.4e\n", (double)f
, (double)sinf(f
));
57 for (i
= 0; i
< 41; i
++) {
58 printf(" cosD(%+20.13e) = %+20.13e\n", d
, cos(d
));
62 for (i
= 0; i
< 41; i
++) {
63 printf(" cosF(%+20.4e) = %+20.4e\n", (double)f
, (double)cosf(f
));
69 for (i
= 0; i
< 41; i
++) {
70 printf(" tanD(%+20.13e) = %+20.13e\n", d
, tan(d
));
74 for (i
= 0; i
< 41; i
++) {
75 printf(" tanF(%+20.4e) = %+20.4e\n", (double)f
, (double)tanf(f
));
81 for (i
= 0; i
< 41; i
++) {
82 printf(" expD(%+20.13e) = %+20.13e\n", d
, exp(d
));
86 for (i
= 0; i
< 41; i
++) {
87 printf(" expF(%+20.4e) = %+20.4e\n", (double)f
, (double)expf(f
));
91 /* -------------------- >= 0 arg -------------------- */
94 for (i
= 0; i
< 21; i
++) {
95 printf(" sqrtD(%+20.13e) = %+20.13e\n", d
, sqrt(d
));
99 for (i
= 0; i
< 21; i
++) {
100 printf(" sqrtF(%+20.4e) = %+20.4e\n", (double)f
, (double)sqrtf(f
));
106 for (i
= 0; i
< 21; i
++) {
107 printf(" logD(%+20.13e) = %+20.13e\n", d
, log(d
));
111 for (i
= 0; i
< 21; i
++) {
112 printf(" logF(%+20.4e) = %+20.4e\n", (double)f
, (double)logf(f
));
118 for (i
= 0; i
< 21; i
++) {
119 printf("log10D(%+20.13e) = %+20.13e\n", d
, log10(d
));
123 for (i
= 0; i
< 21; i
++) {
124 printf("log10F(%+20.4e) = %+20.4e\n", (double)f
, (double)log10f(f
));
128 /* -------------------- -1 .. +1 arg -------------------- */
131 for (i
= 0; i
< 21; i
++) {
132 printf(" asinD(%+20.13e) = %+20.13e\n", d
, asin(d
));
136 for (i
= 0; i
< 21; i
++) {
137 printf(" asinF(%+20.4e) = %+20.4e\n", (double)f
, (double)asinf(f
));
141 /* acos(double) seems very prone to accuracy loss near the end of
142 the range (arg --> +1.0). Hence is different from the rest to
143 stop it getting so close to 1.0. */
145 for (i
= 0; i
< 21; i
++) {
146 printf(" acosD(%+20.13e) = %+20.10e\n", d
, acos(d
));
147 d
+= 0.1 - 1000.0*tinyD
;
150 for (i
= 0; i
< 21; i
++) {
151 printf(" acosF(%+20.4e) = %+20.4e\n", (double)f
, (double)acosf(f
));
157 for (i
= 0; i
< 21; i
++) {
158 printf(" atanD(%+20.13e) = %+20.13e\n", d
, atan(d
));
162 for (i
= 0; i
< 21; i
++) {
163 printf(" atanF(%+20.4e) = %+20.4e\n", (double)f
, (double)atanf(f
));
169 for (i
= 0; i
< 21; i
++) {
170 printf("atan2D(%+20.13e) = %+20.13e\n", d
, atan2(d
, 1.0));
174 for (i
= 0; i
< 21; i
++) {
175 printf("atan2F(%+20.4e) = %+20.4e\n", (double)f
, (double)atan2f(f
,1.0));