2015-05-03 18:15:19 +00:00
|
|
|
/*
|
2021-05-29 17:40:30 +00:00
|
|
|
* PROJECT: ReactOS CRT library
|
|
|
|
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
|
|
|
* PURPOSE: Portable implementation of fabsf
|
|
|
|
* COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
|
2015-05-03 18:15:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
_Check_return_
|
|
|
|
float
|
|
|
|
__cdecl
|
|
|
|
fabsf(
|
|
|
|
_In_ float x)
|
|
|
|
{
|
2021-05-29 17:40:30 +00:00
|
|
|
/* Load the value as uint */
|
|
|
|
unsigned int u32 = *(unsigned int*)&x;
|
|
|
|
|
|
|
|
/* Clear the sign bit */
|
|
|
|
u32 &= ~(1 << 31);
|
2015-05-03 18:15:19 +00:00
|
|
|
|
2021-05-29 17:40:30 +00:00
|
|
|
/* Check for NAN */
|
|
|
|
if (u32 > 0x7F800000)
|
|
|
|
{
|
|
|
|
/* Set error bit */
|
|
|
|
*(unsigned int*)&x |= 0x00400000;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert back to float */
|
|
|
|
return *(float*)&u32;
|
|
|
|
}
|