10 next
= (next
* 1103515245) + 12345;
11 return ((next
>> 16) & 0xffff);
31 } while (!finite(res
));
36 /* Return a random double, but bias for numbers closer to 0 */
42 return ldexp(r
, randi() & 0x1f);
58 /* Frexp of x return a and n, where a * 2**n == x, so test this with a
59 set of random numbers */
60 for (t
= 0; t
< 2; t
++)
62 for (i
= 0; i
< 1000; i
++)
70 newfunc("frexp/ldexp");
72 if (r
> 1.0 || r
< -1.0)
74 /* Answer can never be > 1 or < 1 */
78 gives
= ldexp(r
,pow
);
82 newfunc("frexpf/ldexpf");
83 if (x
> FLT_MIN
&& x
< FLT_MAX
)
85 /* test floats too, but they have a smaller range so make sure x
86 isn't too big. Also x can get smaller than a float can
87 represent to make sure that doesn't happen too */
90 if (r
> 1.0 || r
< -1.0)
92 /* Answer can never be > 1 or < -1 */
96 gives
= ldexpf(r
,pow
);
97 test_mok(gives
,x
, 32);
106 /* test a few numbers manually to make sure frexp/ldexp are not
107 testing as ok because both are broken */
116 test_mok(r
, 0.75, 64);
121 /* Test mod - this is given a real hammering by the strtod type
122 routines, here are some more tests.
126 modf = func(value, &iptr)
128 (*iptr + modf) == value
141 for (i
= 0; i
< 1000; i
++)
147 if (finite(n
) && n
!= 0.0 )
149 double r
= modf(n
, &intpart
);
151 test_mok(intpart
+ r
, n
, 63);
157 for (i
= 0; i
< 1000; i
++)
163 if (nd
< FLT_MAX
&& finitef(nd
) && nd
!= 0.0)
166 double r
= modff(n
, &intpart
);
168 test_mok(intpart
+ r
, n
, 32);
176 Test pow by multiplying logs
184 for (i
= 0; i
< 1000; i
++)
193 n2
= fabs(randy()/100.0);
195 shouldbe
= exp(log(n1
) * n2
);
196 test_mok(shouldbe
, res
,64);
201 for (i
= 0; i
< 1000; i
++)
212 n2
= fabs(randy()/100.0);
214 shouldbe
= expf(logf(n1
) * n2
);
216 test_mok(shouldbe
, res
,28);