1 d19fdc05 2009-08-15 rsc /* Copyright (c) 2002-2006 Lucent Technologies; see LICENSE */
4 91c13e54 2004-02-29 devnull * 64-bit IEEE not-a-number routines.
5 91c13e54 2004-02-29 devnull * This is big/little-endian portable assuming that
6 91c13e54 2004-02-29 devnull * the 64-bit doubles and 64-bit integers have the
7 91c13e54 2004-02-29 devnull * same byte ordering.
10 e5aa96ac 2004-12-26 devnull #include "plan9.h"
11 66f6e2b6 2008-05-10 rsc #include <assert.h>
12 e5aa96ac 2004-12-26 devnull #include "fmt.h"
13 e5aa96ac 2004-12-26 devnull #include "fmtdef.h"
15 040d1d02 2004-09-23 devnull static uvlong uvnan = ((uvlong)0x7FF00000<<32)|0x00000001;
16 040d1d02 2004-09-23 devnull static uvlong uvinf = ((uvlong)0x7FF00000<<32)|0x00000000;
17 040d1d02 2004-09-23 devnull static uvlong uvneginf = ((uvlong)0xFFF00000<<32)|0x00000000;
19 66f6e2b6 2008-05-10 rsc /* gcc sees through the obvious casts. */
20 66f6e2b6 2008-05-10 rsc static uvlong
21 66f6e2b6 2008-05-10 rsc d2u(double d)
27 66f6e2b6 2008-05-10 rsc assert(sizeof(u.d) == sizeof(u.v));
32 66f6e2b6 2008-05-10 rsc static double
33 66f6e2b6 2008-05-10 rsc u2d(uvlong v)
39 66f6e2b6 2008-05-10 rsc assert(sizeof(u.d) == sizeof(u.v));
45 91c13e54 2004-02-29 devnull __NaN(void)
47 66f6e2b6 2008-05-10 rsc return u2d(uvnan);
51 91c13e54 2004-02-29 devnull __isNaN(double d)
53 91c13e54 2004-02-29 devnull uvlong x;
56 ada7ea05 2007-04-06 devnull /* IEEE 754: exponent bits 0x7FF and non-zero mantissa */
57 ada7ea05 2007-04-06 devnull return (x&uvinf) == uvinf && (x&~uvneginf) != 0;
61 91c13e54 2004-02-29 devnull __Inf(int sign)
63 66f6e2b6 2008-05-10 rsc return u2d(sign < 0 ? uvneginf : uvinf);
67 91c13e54 2004-02-29 devnull __isInf(double d, int sign)
69 91c13e54 2004-02-29 devnull uvlong x;
72 91c13e54 2004-02-29 devnull if(sign == 0)
73 91c13e54 2004-02-29 devnull return x==uvinf || x==uvneginf;
74 91c13e54 2004-02-29 devnull else if(sign > 0)
75 91c13e54 2004-02-29 devnull return x==uvinf;
77 91c13e54 2004-02-29 devnull return x==uvneginf;