summaryrefslogtreecommitdiff
path: root/lib/libm_dbl/frexp.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-06-23 15:52:00 +1000
committerDamien George <damien.p.george@gmail.com>2017-06-28 15:12:04 +1000
commit045116551ec06d2619250cffff5e8b56a5f827d1 (patch)
tree314e63ab9307cb0bc4d33486f173ced228209186 /lib/libm_dbl/frexp.c
parent409fc8f9c1c5f07bcbdb6229196775deb4133e03 (diff)
lib: Add libm_dbl, a double-precision math library, from musl-1.1.16.
Diffstat (limited to 'lib/libm_dbl/frexp.c')
-rw-r--r--lib/libm_dbl/frexp.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/libm_dbl/frexp.c b/lib/libm_dbl/frexp.c
new file mode 100644
index 000000000..27b6266ed
--- /dev/null
+++ b/lib/libm_dbl/frexp.c
@@ -0,0 +1,23 @@
+#include <math.h>
+#include <stdint.h>
+
+double frexp(double x, int *e)
+{
+ union { double d; uint64_t i; } y = { x };
+ int ee = y.i>>52 & 0x7ff;
+
+ if (!ee) {
+ if (x) {
+ x = frexp(x*0x1p64, e);
+ *e -= 64;
+ } else *e = 0;
+ return x;
+ } else if (ee == 0x7ff) {
+ return x;
+ }
+
+ *e = ee - 0x3fe;
+ y.i &= 0x800fffffffffffffull;
+ y.i |= 0x3fe0000000000000ull;
+ return y.d;
+}