ref: 1a54d1f0b13124bfbc60a4ecf3ed1f15869c8e3d
parent: 91f426bd7c4eacd1656ae8da651eb9deb93d5763
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Aug 17 14:13:38 EDT 2023
npe: add ldexpf
--- a/include/npe/math.h
+++ b/include/npe/math.h
@@ -57,5 +57,6 @@
double acosh(double x);
double log1p(double x);
double fmax(double x, double y);
+float ldexpf(float x, int n);
#endif
--- /dev/null
+++ b/libnpe/ldexpf.c
@@ -1,0 +1,40 @@
+#include <math.h>
+
+/* taken from musl */
+
+float ldexpf(float x, int n)
+{
+ union {float f; u32int i;} u;
+ float y = x;
+ union {
+ float f;
+ u32int x;
+ }oneP[] = {
+ {.x = 0x7f000000},
+ {.x = 0x800000},
+ {.x = 0x4b800000},
+ };
+
+ if (n > 127) {
+ y *= oneP[0].f;
+ n -= 127;
+ if (n > 127) {
+ y *= oneP[0].f;
+ n -= 127;
+ if (n > 127)
+ n = 127;
+ }
+ } else if (n < -126) {
+ y *= oneP[1].f * oneP[2].f;
+ n += 126 - 24;
+ if (n < -126) {
+ y *= oneP[1].f * oneP[2].f;
+ n += 126 - 24;
+ if (n < -126)
+ n = -126;
+ }
+ }
+ u.i = (u32int)(0x7f+n)<<23;
+ x = y * u.f;
+ return x;
+}
--- a/libnpe/mkfile
+++ b/libnpe/mkfile
@@ -35,6 +35,7 @@
isatty.$O\
isinf.$O\
isnormal.$O\
+ ldexpf.$O\
log1p.$O\
localtime.$O\
log2.$O\