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