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/ape/lib/ap/plan9/frexp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'sys/src/ape/lib/ap/plan9') diff --git a/sys/src/ape/lib/ap/plan9/frexp.c b/sys/src/ape/lib/ap/plan9/frexp.c index 588f90cee..0d81f52c7 100644 --- a/sys/src/ape/lib/ap/plan9/frexp.c +++ b/sys/src/ape/lib/ap/plan9/frexp.c @@ -6,6 +6,7 @@ #define MASK 0x7ffL #define SHIFT 20 #define BIAS 1022L +#define SIG 52 typedef union { @@ -25,13 +26,18 @@ typedef union double frexp(double d, int *ep) { - Cheat x; + Cheat 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.d = d; + a.d = fabs(d); + if((a.ms >> SHIFT) == 0){ /* normalize subnormal numbers */ + x.d = (double)(1ULL<> SHIFT) & MASK) - BIAS; x.ms &= ~(MASK << SHIFT); x.ms |= BIAS << SHIFT; -- cgit v1.2.3