xref: /reactos/sdk/lib/ucrt/math/_fdclass.c (revision 59c55e00)
1 //
2 // _fdclass.c
3 //
4 //      Copyright (c) 2024 Timo Kreuzer
5 //
6 // Implementation of _fdclass.
7 //
8 // SPDX-License-Identifier: MIT
9 //
10 
11 #include <math.h>
12 #include <stdint.h>
13 
14 #ifdef _MSC_VER
15 #pragma function(_fdclass)
16 #endif
17 
18 //
19 // Returns the floating-point classification of _X.
20 //
21 //     FP_NAN - A quiet, signaling, or indeterminate NaN
22 //     FP_INFINITE - A positive or negative infinity
23 //     FP_NORMAL - A positive or negative normalized non-zero value
24 //     FP_SUBNORMAL - A positive or negative subnormal (denormalized) value
25 //     FP_ZERO - A positive or negative zero value
26 //
27 _Check_return_
28 short
29 __cdecl
_fdclass(_In_ float _X)30 _fdclass(_In_ float _X)
31 {
32     union { float f; uint32_t ui32; } u = { _X };
33     uint32_t e = u.ui32 & 0x7F800000u;
34     uint32_t m = u.ui32 & 0x007FFFFFu;
35 
36     if (e == 0x7F800000u)
37     {
38         return m ? FP_NAN : FP_INFINITE;
39     }
40     else if (e == 0)
41     {
42         return m ? FP_SUBNORMAL : FP_ZERO;
43     }
44     else
45     {
46         return FP_NORMAL;
47     }
48 }
49