1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS system libraries 4 * FILE: lib/sdk/crt/float/fpclass.c 5 * PURPOSE: Floating-point classes 6 * PROGRAMER: Pierre Schweitzer (pierre@reactos.org) 7 * REFERENCE: http://babbage.cs.qc.cuny.edu/IEEE-754/References.xhtml 8 */ 9 10 #include <precomp.h> 11 #include <float.h> 12 #include <internal/ieee.h> 13 14 /* 15 * @implemented 16 */ 17 int _fpclass(double __d) 18 { 19 union 20 { 21 double* __d; 22 double_s* d; 23 } d; 24 d.__d = &__d; 25 26 27 /* With 0x7ff, it can only be infinity or NaN */ 28 if (d.d->exponent == 0x7ff) 29 { 30 if (d.d->mantissah == 0 && d.d->mantissal == 0) 31 { 32 return (d.d->sign == 0) ? _FPCLASS_PINF : _FPCLASS_NINF; 33 } 34 /* Windows will never return Signaling NaN */ 35 else 36 { 37 return _FPCLASS_QNAN; 38 } 39 } 40 41 /* With 0, it can only be zero or denormalized number */ 42 if (d.d->exponent == 0) 43 { 44 if (d.d->mantissah == 0 && d.d->mantissal == 0) 45 { 46 return (d.d->sign == 0) ? _FPCLASS_PZ : _FPCLASS_NZ; 47 } 48 else 49 { 50 return (d.d->sign == 0) ? _FPCLASS_PD : _FPCLASS_ND; 51 } 52 } 53 /* Only remain normalized numbers */ 54 else 55 { 56 return (d.d->sign == 0) ? _FPCLASS_PN : _FPCLASS_NN; 57 } 58 } 59