From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/stdlib/frexp.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/stdlib/frexp.c (limited to 'src/stdlib/frexp.c') diff --git a/src/stdlib/frexp.c b/src/stdlib/frexp.c new file mode 100644 index 00000000..ae82cb30 --- /dev/null +++ b/src/stdlib/frexp.c @@ -0,0 +1,23 @@ +#include +#include + +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; +} -- cgit v1.2.1