From c5d5d574cbfa96d0f6c1db24d1e072c472627e41 Mon Sep 17 00:00:00 2001 From: Ondřej Bílka Date: Thu, 17 Oct 2013 16:03:24 +0200 Subject: Format floating routines. --- sysdeps/ieee754/dbl-64/s_modf.c | 84 ++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 35 deletions(-) (limited to 'sysdeps/ieee754/dbl-64/s_modf.c') diff --git a/sysdeps/ieee754/dbl-64/s_modf.c b/sysdeps/ieee754/dbl-64/s_modf.c index b9911c1af6..1dce6381ae 100644 --- a/sysdeps/ieee754/dbl-64/s_modf.c +++ b/sysdeps/ieee754/dbl-64/s_modf.c @@ -25,45 +25,59 @@ static const double one = 1.0; double -__modf(double x, double *iptr) +__modf (double x, double *iptr) { - int32_t i0,i1,j0; - u_int32_t i; - EXTRACT_WORDS(i0,i1,x); - j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */ - if(j0<20) { /* integer part in high x */ - if(j0<0) { /* |x|<1 */ - INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */ - return x; - } else { - i = (0x000fffff)>>j0; - if(((i0&i)|i1)==0) { /* x is integral */ - *iptr = x; - INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */ - return x; - } else { - INSERT_WORDS(*iptr,i0&(~i),0); - return x - *iptr; - } + int32_t i0, i1, j0; + u_int32_t i; + EXTRACT_WORDS (i0, i1, x); + j0 = ((i0 >> 20) & 0x7ff) - 0x3ff; /* exponent of x */ + if (j0 < 20) /* integer part in high x */ + { + if (j0 < 0) /* |x|<1 */ + { + INSERT_WORDS (*iptr, i0 & 0x80000000, 0); /* *iptr = +-0 */ + return x; + } + else + { + i = (0x000fffff) >> j0; + if (((i0 & i) | i1) == 0) /* x is integral */ + { + *iptr = x; + INSERT_WORDS (x, i0 & 0x80000000, 0); /* return +-0 */ + return x; } - } else if (__builtin_expect(j0>51, 0)) { /* no fraction part */ - *iptr = x*one; - /* We must handle NaNs separately. */ - if (j0 == 0x400 && ((i0 & 0xfffff) | i1)) - return x*one; - INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */ - return x; - } else { /* fraction part in low x */ - i = ((u_int32_t)(0xffffffff))>>(j0-20); - if((i1&i)==0) { /* x is integral */ - *iptr = x; - INSERT_WORDS(x,i0&0x80000000,0); /* return +-0 */ - return x; - } else { - INSERT_WORDS(*iptr,i0,i1&(~i)); - return x - *iptr; + else + { + INSERT_WORDS (*iptr, i0 & (~i), 0); + return x - *iptr; } } + } + else if (__builtin_expect (j0 > 51, 0)) /* no fraction part */ + { + *iptr = x * one; + /* We must handle NaNs separately. */ + if (j0 == 0x400 && ((i0 & 0xfffff) | i1)) + return x * one; + INSERT_WORDS (x, i0 & 0x80000000, 0); /* return +-0 */ + return x; + } + else /* fraction part in low x */ + { + i = ((u_int32_t) (0xffffffff)) >> (j0 - 20); + if ((i1 & i) == 0) /* x is integral */ + { + *iptr = x; + INSERT_WORDS (x, i0 & 0x80000000, 0); /* return +-0 */ + return x; + } + else + { + INSERT_WORDS (*iptr, i0, i1 & (~i)); + return x - *iptr; + } + } } weak_alias (__modf, modf) #ifdef NO_LONG_DOUBLE -- cgit 1.4.1