xref: /plan9/sys/src/cmd/unix/drawterm/libc/nan64.c (revision 8ccd4a6360d974db7bd7bbd4f37e7018419ea908)
1 /*
2  * 64-bit IEEE not-a-number routines.
3  * This is big/little-endian portable assuming that
4  * the 64-bit doubles and 64-bit integers have the
5  * same byte ordering.
6  */
7 
8 #include <u.h>
9 #include <libc.h>
10 #include "nan.h"
11 
12 // typedef unsigned long long uvlong;
13 // typedef unsigned long ulong;
14 
15 static uvlong uvnan    = 0x7FF0000000000001ULL;
16 static uvlong uvinf    = 0x7FF0000000000000ULL;
17 static uvlong uvneginf = 0xFFF0000000000000ULL;
18 
19 double
20 __NaN(void)
21 {
22 	return *(double*)(void*)&uvnan;
23 }
24 
25 int
26 __isNaN(double d)
27 {
28 	uvlong x = *(uvlong*)(void*)&d;
29 	return (ulong)(x>>32)==0x7FF00000 && !__isInf(d, 0);
30 }
31 
32 double
33 __Inf(int sign)
34 {
35 	if(sign < 0)
36 		return *(double*)(void*)&uvinf;
37 	else
38 		return *(double*)(void*)&uvneginf;
39 }
40 
41 int
42 __isInf(double d, int sign)
43 {
44 	uvlong x;
45 
46 	x = *(uvlong*)(void*)&d;
47 	if(sign == 0)
48 		return x==uvinf || x==uvneginf;
49 	else if(sign > 0)
50 		return x==uvinf;
51 	else
52 		return x==uvneginf;
53 }
54 
55 
56