xref: /inferno-os/emu/Nt/fp.c (revision d0e1d143ef6f03c75c008c7ec648859dd260cbab)
1 typedef	unsigned long	ulong;
2 typedef	unsigned int	uint;
3 typedef	unsigned short	ushort;
4 typedef	unsigned char	uchar;
5 typedef	signed char	schar;
6 
7 #include <float.h>
8 #include "mathi.h"
9 
10 #define	NANEXP	(2047<<20)
11 #define	NANMASK	(2047<<20)
12 #define	NANSIGN	(1<<31)
13 
14 int	isInf(double, int);
15 
16 double
17 NaN(void)
18 {
19 	union
20 	{
21 		double	d;
22 		long	x[2];
23 	} a;
24 
25 	a.x[1] = NANEXP;
26 	a.x[0] = 1;
27 	return a.d;
28 }
29 
30 int
31 isNaN(double d)
32 {
33 	union
34 	{
35 		double	d;
36 		long	x[2];
37 	} a;
38 
39 	a.d = d;
40 	if((a.x[1] & NANMASK) != NANEXP)
41 		return 0;
42 	return !isInf(d, 0);
43 }
44 
45 double
46 Inf(int sign)
47 {
48 	union
49 	{
50 		double	d;
51 		long	x[2];
52 	} a;
53 
54 	a.x[1] = NANEXP;
55 	a.x[0] = 0;
56 	if(sign < 0)
57 		a.x[1] |= NANSIGN;
58 	return a.d;
59 }
60 
61 int
62 isInf(double d, int sign)
63 {
64 	union
65 	{
66 		double	d;
67 		long	x[2];
68 	} a;
69 
70 	a.d = d;
71 	if(a.x[0] != 0)
72 		return 0;
73 	if(a.x[1] == NANEXP)
74 		return sign >= 0;
75 	if(a.x[1] == (NANEXP|NANSIGN))
76 		return sign <= 0;
77 	return 0;
78 }
79 
80 ulong
81 getfcr(void)
82 {
83 	return getFPcontrol();
84 }
85 
86 void
87 setfcr(ulong m)
88 {
89 	FPcontrol(m, ~0);
90 }
91 
92 ulong
93 getfsr(void)
94 {
95 	return getFPstatus();
96 }
97 
98 void
99 setfsr(ulong m)
100 {
101 	FPstatus(m, ~0);
102 }
103 
104 
105 
106 
107 
108