@@ -182,46 +182,19 @@ double stdlib_base_ldexp( const double frac, const int32_t exp );
182182
183183```c
184184#include "stdlib/math/base/special/ldexp.h"
185- #include "stdlib/math/base/special/frexp.h"
186- #include "stdlib/math/base/special/pow.h"
187- #include <stdlib.h>
188185#include <stdint.h>
189186#include <stdio.h>
190- #include <inttypes.h>
191- #include <math.h>
192-
193- static double rand_double() {
194- int r = rand();
195- return (double)r / ( (double)RAND_MAX + 1.0 );
196- }
197187
198188int main( void ) {
199- double sign;
200- double frac;
201- int32_t exp;
202- double x;
203- double v;
189+ double y;
204190 int i;
205191
206- for ( i = 0; i < 100; i++ ) {
207- if ( rand_double() < 0.5 ) {
208- sign = -1.0;
209- } else {
210- sign = 1.0;
211- }
212-
213- // Generate a random number:
214- frac = rand_double() * 10.0;
215- exp = (int32_t)( rand_double() * 616.0 ) - 308;
216- x = sign * frac * stdlib_base_pow( 10.0, (double)exp );
217-
218- // Break the number into a normalized fraction and an integer power of two:
219- stdlib_base_frexp( x, &frac, &exp );
220-
221- // Reconstitute the original number:
222- v = stdlib_base_ldexp( frac, exp );
192+ const double frac[] = { 0.5, 5.0, 0.0, 3.5, 7.9 };
193+ const int32_t exp[] = { 3, -2, 20, 39, 14 };
223194
224- printf( "%e = %lf * 2^%" PRId32 " = %e\n", x, frac, exp, v );
195+ for ( i = 0; i < 5; i++ ) {
196+ y = stdlib_base_ldexp( frac[ i ], exp[ i ] );
197+ printf( "ldexp(%lf, %d) = %lf\n", frac[ i ], exp[ i ], y );
225198 }
226199}
227200```
0 commit comments