https://git.reactos.org/?p=reactos.git;a=commitdiff;h=59c55e003e706ec9ccd7d…
commit 59c55e003e706ec9ccd7df80dcdc2b96eb0e3226
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Fri Nov 15 16:53:39 2024 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Sun Jan 26 18:08:55 2025 +0200
[UCRT:MATH] Implement _dclass, _fdclass
---
sdk/lib/ucrt/math/_dclass.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
sdk/lib/ucrt/math/_fdclass.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
sdk/lib/ucrt/math/math.cmake | 2 ++
3 files changed, 98 insertions(+)
diff --git a/sdk/lib/ucrt/math/_dclass.c b/sdk/lib/ucrt/math/_dclass.c
new file mode 100644
index 00000000000..aeeff8ccde0
--- /dev/null
+++ b/sdk/lib/ucrt/math/_dclass.c
@@ -0,0 +1,48 @@
+//
+// _dclass.c
+//
+// Copyright (c) 2024 Timo Kreuzer
+//
+// Implementation of _dclass.
+//
+// SPDX-License-Identifier: MIT
+//
+
+#include <math.h>
+#include <stdint.h>
+
+#ifdef _MSC_VER
+#pragma function(_dclass)
+#endif
+
+//
+// Returns the floating-point classification of _X.
+//
+// FP_NAN - A quiet, signaling, or indeterminate NaN
+// FP_INFINITE - A positive or negative infinity
+// FP_NORMAL - A positive or negative normalized non-zero value
+// FP_SUBNORMAL - A positive or negative subnormal (denormalized) value
+// FP_ZERO - A positive or negative zero value
+//
+_Check_return_
+short
+__cdecl
+_dclass(_In_ double _X)
+{
+ union { double f; uint64_t ui64; } u = { _X };
+ uint64_t e = u.ui64 & 0x7FF0000000000000ull;
+ uint64_t m = u.ui64 & 0x000FFFFFFFFFFFFFull;
+
+ if (e == 0x7FF0000000000000ull)
+ {
+ return m ? FP_NAN : FP_INFINITE;
+ }
+ else if (e == 0)
+ {
+ return m ? FP_SUBNORMAL : FP_ZERO;
+ }
+ else
+ {
+ return FP_NORMAL;
+ }
+}
diff --git a/sdk/lib/ucrt/math/_fdclass.c b/sdk/lib/ucrt/math/_fdclass.c
new file mode 100644
index 00000000000..4714a9d6664
--- /dev/null
+++ b/sdk/lib/ucrt/math/_fdclass.c
@@ -0,0 +1,48 @@
+//
+// _fdclass.c
+//
+// Copyright (c) 2024 Timo Kreuzer
+//
+// Implementation of _fdclass.
+//
+// SPDX-License-Identifier: MIT
+//
+
+#include <math.h>
+#include <stdint.h>
+
+#ifdef _MSC_VER
+#pragma function(_fdclass)
+#endif
+
+//
+// Returns the floating-point classification of _X.
+//
+// FP_NAN - A quiet, signaling, or indeterminate NaN
+// FP_INFINITE - A positive or negative infinity
+// FP_NORMAL - A positive or negative normalized non-zero value
+// FP_SUBNORMAL - A positive or negative subnormal (denormalized) value
+// FP_ZERO - A positive or negative zero value
+//
+_Check_return_
+short
+__cdecl
+_fdclass(_In_ float _X)
+{
+ union { float f; uint32_t ui32; } u = { _X };
+ uint32_t e = u.ui32 & 0x7F800000u;
+ uint32_t m = u.ui32 & 0x007FFFFFu;
+
+ if (e == 0x7F800000u)
+ {
+ return m ? FP_NAN : FP_INFINITE;
+ }
+ else if (e == 0)
+ {
+ return m ? FP_SUBNORMAL : FP_ZERO;
+ }
+ else
+ {
+ return FP_NORMAL;
+ }
+}
diff --git a/sdk/lib/ucrt/math/math.cmake b/sdk/lib/ucrt/math/math.cmake
index 4eadd9f107d..69f213e743f 100644
--- a/sdk/lib/ucrt/math/math.cmake
+++ b/sdk/lib/ucrt/math/math.cmake
@@ -1,4 +1,6 @@
list(APPEND UCRT_MATH_SOURCES
+ math/_dclass.c
+ math/_fdclass.c
math/matherr.cpp
)