ref: 1cf523a5e0dc72fd9d41aa434e3359ff08c5406e
parent: 1a54d1f0b13124bfbc60a4ecf3ed1f15869c8e3d
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Aug 17 14:15:01 EDT 2023
npe: add hypotf
--- a/include/npe/math.h
+++ b/include/npe/math.h
@@ -58,5 +58,6 @@
double log1p(double x);
double fmax(double x, double y);
float ldexpf(float x, int n);
+float hypotf(float x, float y);
#endif
--- /dev/null
+++ b/libnpe/hypotf.c
@@ -1,0 +1,44 @@
+#include <math.h>
+
+/* taken from musl */
+
+float
+hypotf(float x, float y)
+{
+ union {float f; u32int i;} ux = {x}, uy = {y}, ut;
+ float z;
+ union {
+ float f;
+ u32int x;
+ }oneP[] = {
+ {.x = 0x6c800000},
+ {.x = 0x12800000},
+ };
+
+ ux.i &= -1U>>1;
+ uy.i &= -1U>>1;
+ if (ux.i < uy.i) {
+ ut = ux;
+ ux = uy;
+ uy = ut;
+ }
+
+ x = ux.f;
+ y = uy.f;
+ if (uy.i == 0xff<<23)
+ return y;
+ if (ux.i >= 0xff<<23 || uy.i == 0 || ux.i - uy.i >= 25<<23)
+ return x + y;
+
+ z = 1;
+ if (ux.i >= (0x7f+60)<<23) {
+ z = oneP[0].f;
+ x *= oneP[1].f;
+ y *= oneP[1].f;
+ } else if (uy.i < (0x7f-60)<<23) {
+ z = oneP[1].f;
+ x *= oneP[0].f;
+ y *= oneP[0].f;
+ }
+ return z*sqrtf((double)x*x + (double)y*y);
+}
--- a/libnpe/mkfile
+++ b/libnpe/mkfile
@@ -29,6 +29,7 @@
getenv.$O\
gettimeofday.$O\
gmtime.$O\
+ hypotf.$O\
iconv.$O\
iconv_close.$O\
iconv_open.$O\