From af313dec6b7698b6f948b97669aa7be91717a451 Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Fri, 21 Jun 2024 13:49:33 +0200 Subject: LibC: Add ldexp --- userland/libc/math/ldexp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 userland/libc/math/ldexp.c (limited to 'userland') 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 +#include + +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; +} -- cgit v1.2.3