branch update for HEAD-2003021201
[reactos.git] / lib / msvcrt / 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 fpclass_t _fpclass(double __d)
31 {
32         double_t *d = (double_t *)&__d;
33
34         if ( d->exponent == 0 ) {
35                 if ( d->mantissah == 0 &&  d->mantissal == 0 ) {
36                         if ( d->sign ==0 )
37                                 return FP_NZERO;
38                         else
39                                 return FP_PZERO;
40                 } else {
41                         if ( d->sign ==0 )
42                                 return FP_NDENORM;
43                         else
44                                 return FP_PDENORM;
45                 }
46         }
47         if (d->exponent == 0x7ff ) {
48                 if ( d->mantissah == 0 &&  d->mantissal == 0 ) {
49                         if ( d->sign ==0 )
50                                 return FP_NINF;
51                         else
52                                 return FP_PINF;
53                 } 
54                 else if ( d->mantissah == 0 &&  d->mantissal != 0 ) {
55                         return FP_QNAN;
56                 }
57                 else if ( d->mantissah == 0 &&  d->mantissal != 0 ) {
58                         return FP_SNAN;
59                 }
60         
61         }
62         return 0;
63 }