mirror of
https://github.com/reactos/reactos.git
synced 2024-08-28 14:18:41 +00:00
39 lines
748 B
C
39 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;
|
||
|
}
|