X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmath%2Ffrexp.c;fp=src%2Fmath%2Ffrexp.c;h=27b6266ed0c1d7c5dadd06ecc186a994fdcd1c52;hb=b69f695acedd4ce2798ef9ea28d834ceccc789bd;hp=0000000000000000000000000000000000000000;hpb=d46cf2e14cc4df7cc75e77d7009fcb6df1f48a33;p=musl diff --git a/src/math/frexp.c b/src/math/frexp.c new file mode 100644 index 00000000..27b6266e --- /dev/null +++ b/src/math/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; +}