diff options
Diffstat (limited to 'userland')
-rw-r--r-- | userland/libc/math/ldexp.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/userland/libc/math/ldexp.c b/userland/libc/math/ldexp.c new file mode 100644 index 0000000..06d4cd0 --- /dev/null +++ b/userland/libc/math/ldexp.c @@ -0,0 +1,16 @@ +#include <float.h> +#include <math.h> + +double ldexp(double x, int exp) { + double sign = (x < 0.0) ? (-1) : (1); + + if (exp > 29) { + return sign * HUGE_VAL; + } + double two_exp = 2 << exp; + + if (x > DBL_MAX / two_exp) { + return sign * HUGE_VAL; + } + return x * two_exp; +} |