mirror of
https://github.com/reactos/reactos.git
synced 2024-11-20 06:15:26 +00:00
b85afdfd25
Note: older versions of ML64 are broken and don't understand the register form of movq. See https://stackoverflow.com/questions/24789339/move-quadword-between-xmm-and-general-purpose-register-in-ml64
38 lines
748 B
C
38 lines
748 B
C
/*
|
|
* PROJECT: ReactOS CRT library
|
|
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
|
* PURPOSE: Portable implementation of fabs
|
|
* COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
|
|
*/
|
|
|
|
#include <math.h>
|
|
|
|
#ifdef _MSC_VER
|
|
#pragma function(fabs)
|
|
#endif
|
|
|
|
_Check_return_
|
|
double
|
|
__cdecl
|
|
fabs(
|
|
_In_ double x)
|
|
{
|
|
/* Load the value as uint64 */
|
|
unsigned long long u64 = *(unsigned long long*)&x;
|
|
|
|
/* Clear the sign bit */
|
|
u64 &= ~(1ULL << 63);
|
|
|
|
/* Check for NAN */
|
|
if (u64 > 0x7FF0000000000000ull)
|
|
{
|
|
#ifdef _M_IX86
|
|
/* Set error bit */
|
|
*(unsigned long long*)&x |= 0x0008000000000000ull;
|
|
#endif
|
|
return x;
|
|
}
|
|
|
|
/* Convert back to double */
|
|
return *(double*)&u64;
|
|
}
|