summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-06-21 13:49:33 +0200
committerAnton Kling <anton@kling.gg>2024-06-21 13:49:33 +0200
commitaf313dec6b7698b6f948b97669aa7be91717a451 (patch)
tree37e64a195a89027228850798f40918c309a8bcbf /userland
parent7045cec0314ca2643182ca3df7a483ee98c6c1ae (diff)
LibC: Add ldexp
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/math/ldexp.c16
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;
+}