summaryrefslogtreecommitdiff
path: root/lib/libm/scalbn.c
diff options
context:
space:
mode:
authorKacper <kacper@mail.openlinux.dev>2025-12-09 19:20:15 +0100
committerKacper <kacper@mail.openlinux.dev>2025-12-09 19:20:15 +0100
commit885f5974cdf65b59415837ae97f5a14ef1350670 (patch)
tree66ac13de29c7f4932c5fcae11773df574e4e256a /lib/libm/scalbn.c
parent8f9e448b2ef6db7cd905540c21f3c5b190e7a1e7 (diff)
feat: add gzip and new headers
Diffstat (limited to 'lib/libm/scalbn.c')
-rw-r--r--lib/libm/scalbn.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/libm/scalbn.c b/lib/libm/scalbn.c
new file mode 100644
index 00000000..d38d4338
--- /dev/null
+++ b/lib/libm/scalbn.c
@@ -0,0 +1,36 @@
+#include <math.h>
+#include <stdint.h>
+
+double scalbn(double x, int n)
+{
+ union {
+ double f;
+ uint64_t i;
+ } u;
+ double_t y = x;
+
+ if (n > 1023) {
+ y *= 0x1p1023;
+ n -= 1023;
+ if (n > 1023) {
+ y *= 0x1p1023;
+ n -= 1023;
+ if (n > 1023)
+ n = 1023;
+ }
+ } else if (n < -1022) {
+ /* make sure final n < -53 to avoid double
+ rounding in the subnormal range */
+ y *= 0x1p-1022 * 0x1p53;
+ n += 1022 - 53;
+ if (n < -1022) {
+ y *= 0x1p-1022 * 0x1p53;
+ n += 1022 - 53;
+ if (n < -1022)
+ n = -1022;
+ }
+ }
+ u.i = (uint64_t)(0x3ff + n) << 52;
+ x = y * u.f;
+ return x;
+}