From decade55c63a802e288beb718de5d6b3cb81b0cc Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Wed, 1 May 2013 16:44:04 +0200 Subject: frexp: handle NaN values (from sources) --- sys/src/libc/port/frexp.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'sys/src/libc/port') diff --git a/sys/src/libc/port/frexp.c b/sys/src/libc/port/frexp.c index 7809bd151..669f12152 100644 --- a/sys/src/libc/port/frexp.c +++ b/sys/src/libc/port/frexp.c @@ -9,18 +9,24 @@ #define MASK 0x7ffL #define SHIFT 20 #define BIAS 1022L +#define SIG 52 double frexp(double d, int *ep) { - FPdbleword x; + FPdbleword x, a; - if(d == 0) { - *ep = 0; - return 0; - } + *ep = 0; + /* order matters: only isNaN can operate on NaN */ + if(isNaN(d) || isInf(d, 0) || d == 0) + return d; x.x = d; - *ep = ((x.hi >> SHIFT) & MASK) - BIAS; + a.x = fabs(d); + if((a.hi >> SHIFT) == 0){ /* normalize subnormal numbers */ + x.x = (double)(1ULL<> SHIFT) & MASK) - BIAS; x.hi &= ~(MASK << SHIFT); x.hi |= BIAS << SHIFT; return x.x; -- cgit v1.2.3