diff options
| author | Charles.Forsyth <devnull@localhost> | 2009-04-01 22:54:06 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2009-04-01 22:54:06 +0000 |
| commit | 4eb166cf184c1f102fb79e31b1465ea3e2021c39 (patch) | |
| tree | 0e1bd8c059324d5cb99d625a67398e48a9ffce95 /libkern/nan-spim.c | |
| parent | a9b1d9c7f57ec21ff8be147f5c949966b966e519 (diff) | |
20090401-2350
Diffstat (limited to 'libkern/nan-spim.c')
| -rw-r--r-- | libkern/nan-spim.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/libkern/nan-spim.c b/libkern/nan-spim.c new file mode 100644 index 00000000..2152925a --- /dev/null +++ b/libkern/nan-spim.c @@ -0,0 +1,69 @@ +#include <lib9.h> + +#define NANEXP (2047<<20) +#define NANMASK (2047<<20) +#define NANSIGN (1<<31) + +double +NaN(void) +{ + union + { + double d; + long x[2]; + } a; + + a.x[1] = NANEXP; + a.x[0] = 1; + return a.d; +} + +int +isNaN(double d) +{ + union + { + double d; + long x[2]; + } a; + + a.d = d; + if((a.x[1] & NANMASK) != NANEXP) + return 0; + return !isInf(d, 0); +} + +double +Inf(int sign) +{ + union + { + double d; + long x[2]; + } a; + + a.x[1] = NANEXP; + a.x[0] = 0; + if(sign < 0) + a.x[1] |= NANSIGN; + return a.d; +} + +int +isInf(double d, int sign) +{ + union + { + double d; + long x[2]; + } a; + + a.d = d; + if(a.x[0] != 0) + return 0; + if(a.x[1] == NANEXP) + return sign >= 0; + if(a.x[1] == (NANEXP|NANSIGN)) + return sign <= 0; + return 0; +} |
