Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

#include "stdlib/math/base/special/ldexp.h"
#include "stdlib/math/base/special/frexp.h"
#include "stdlib/math/base/special/pow.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <inttypes.h>
#include <math.h>

// TODO: replace use of `pow` with stdlib_base_pow()

static double rand_double() {
int r = rand();
Expand All @@ -34,29 +32,29 @@ static double rand_double() {

int main( void ) {
double sign;
double frac;
int32_t exp;
double x;
double v;
int i;

for ( i = 0; i < 100; i++ ) {
if ( rand_double() < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
// Generate a random number:
frac = rand_double() * 10.0;
exp = (int32_t)( rand_double()*616.0 ) - 308;
x = sign * frac * pow( 10.0, exp );

// Break the number into a normalized fraction and an integer power of two:
stdlib_base_frexp( x, &frac, &exp );

// Reconstitute the original number:
v = stdlib_base_ldexp( frac, exp );

printf( "%e = %lf * 2^%" PRId32 " = %e\n", x, frac, exp, v );
}
double frac;
int32_t exp;
double x;
double v;
int i;

for ( i = 0; i < 100; i++ ) {
if ( rand_double() < 0.5 ) {
sign = -1.0;
} else {
sign = 1.0;
}
// Generate a random number:
frac = rand_double() * 10.0;
exp = (int32_t)( rand_double()*616.0 ) - 308;
x = sign * frac * stdlib_base_pow( 10.0, exp );

// Break the number into a normalized fraction and an integer power of two:
stdlib_base_frexp( x, &frac, &exp );

// Reconstitute the original number:
v = stdlib_base_ldexp( frac, exp );

printf( "%e = %lf * 2^%" PRId32 " = %e\n", x, frac, exp, v );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"@stdlib/constants/float64/max-base2-exponent",
"@stdlib/constants/float64/max-base2-exponent-subnormal",
"@stdlib/constants/float64/exponent-bias",
"@stdlib/math/base/special/frexp"
"@stdlib/math/base/special/frexp",
"@stdlib/math/base/special/pow"
]
},
{
Expand Down