[CRT:MATH] Move some math functions from ucrt to crt

This commit is contained in:
Timo Kreuzer 2025-05-11 12:02:39 +03:00
parent a9ee20cb9a
commit b734e3ba63
8 changed files with 64 additions and 68 deletions

View file

@ -0,0 +1,46 @@
/*
* PROJECT: ReactOS CRT
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Implementation of _dclass.
* COPYRIGHT: Copyright 2025 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <math.h>
#include <stdint.h>
#if defined(_MSC_VER) && (_MSC_VER >= 1922)
_Check_return_ short __cdecl _dclass(_In_ double _X);
#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;
}
}

23
sdk/lib/crt/math/_dtest.c Normal file
View file

@ -0,0 +1,23 @@
/*
* PROJECT: ReactOS CRT
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Implementation of _dtest.
* COPYRIGHT: Copyright 2025 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <math.h>
_Check_return_ short __cdecl _dclass(_In_ double _X);
#if defined(_MSC_VER) && (_MSC_VER >= 1922)
_Check_return_ short __cdecl _dtest(_In_ double* _Px);
#pragma function(_dtest)
#endif
_Check_return_
short
__cdecl
_dtest(_In_ double* _Px)
{
return _dclass(*_Px);
}

View file

@ -0,0 +1,46 @@
/*
* PROJECT: ReactOS CRT
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Implementation of _fdclass.
* COPYRIGHT: Copyright 2025 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <math.h>
#include <stdint.h>
#if defined(_MSC_VER) && (_MSC_VER >= 1922)
_Check_return_ short __cdecl _fdclass(_In_ float _X);
#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;
}
}

View file

@ -0,0 +1,23 @@
/*
* PROJECT: ReactOS CRT
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Implementation of _fdtest.
* COPYRIGHT: Copyright 2025 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <math.h>
_Check_return_ short __cdecl _fdclass(_In_ float _X);
#if defined(_MSC_VER) && (_MSC_VER >= 1922)
_Check_return_ short __cdecl _fdtest(_In_ float* _Px);
#pragma function(_fdtest)
#endif
_Check_return_
short
__cdecl
_fdtest(_In_ float* _Px)
{
return _fdclass(*_Px);
}

View file

@ -3,8 +3,12 @@ include_directories(libm_sse2)
list(APPEND LIBCNTPR_MATH_SOURCE
math/_chgsignf.c
math/_dclass.c
math/_dsign.c
math/_dtest.c
math/_fdclass.c
math/_fdsign.c
math/_fdtest.c
math/_finite.c
math/_finitef.c
math/_isnan.c