06c404f5ead3f80d9d401b97bfbeb8189ba0d7d8
[reactos.git] / reactos / lib / crtdll / float / fpclass.c
1 #include <crtdll/float.h>
2 #include <crtdll/math.h>
3 #include <crtdll/internal/ieee.h>
4
5 #define _FPCLASS_SNAN 0x0001 /* signaling NaN */
6 #define _FPCLASS_QNAN 0x0002 /* quiet NaN */
7 #define _FPCLASS_NINF 0x0004 /* negative infinity */
8 #define _FPCLASS_NN 0x0008 /* negative normal */
9 #define _FPCLASS_ND 0x0010 /* negative denormal */
10 #define _FPCLASS_NZ 0x0020 /* -0 */
11 #define _FPCLASS_PZ 0x0040 /* +0 */
12 #define _FPCLASS_PD 0x0080 /* positive denormal */
13 #define _FPCLASS_PN 0x0100 /* positive normal */
14 #define _FPCLASS_PINF 0x0200 /* positive infinity */
15
16 #define FP_SNAN 0x0001 // signaling NaN
17 #define FP_QNAN 0x0002 // quiet NaN
18 #define FP_NINF 0x0004 // negative infinity
19 #define FP_PINF 0x0200 // positive infinity
20 #define FP_NDENORM 0x0008 // negative denormalized non-zero
21 #define FP_PDENORM 0x0010 // positive denormalized non-zero
22 #define FP_NZERO 0x0020 // negative zero
23 #define FP_PZERO 0x0040 // positive zero
24 #define FP_NNORM 0x0080 // negative normalized non-zero
25 #define FP_PNORM 0x0100 // positive normalized non-zero
26
27 typedef int fpclass_t;
28
29 fpclass_t _fpclass(double __d)
30 {
31 double_t *d = (double_t *)&__d;
32
33 if ( d->exponent == 0 ) {
34 if ( d->mantissah == 0 && d->mantissal == 0 ) {
35 if ( d->sign ==0 )
36 return FP_NZERO;
37 else
38 return FP_PZERO;
39 } else {
40 if ( d->sign ==0 )
41 return FP_NDENORM;
42 else
43 return FP_PDENORM;
44 }
45 }
46 if (d->exponent == 0x7ff ) {
47 if ( d->mantissah == 0 && d->mantissal == 0 ) {
48 if ( d->sign ==0 )
49 return FP_NINF;
50 else
51 return FP_PINF;
52 }
53 else if ( d->mantissah == 0 && d->mantissal != 0 ) {
54 return FP_QNAN;
55 }
56 else if ( d->mantissah == 0 && d->mantissal != 0 ) {
57 return FP_SNAN;
58 }
59
60 }
61
62 return 0;
63 }
64
65