diff options
author | Anton Kling <anton@kling.gg> | 2024-06-21 13:49:33 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-06-21 13:49:33 +0200 |
commit | af313dec6b7698b6f948b97669aa7be91717a451 (patch) | |
tree | 37e64a195a89027228850798f40918c309a8bcbf /userland | |
parent | 7045cec0314ca2643182ca3df7a483ee98c6c1ae (diff) |
LibC: Add ldexp
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; +} |