* PROJECT: ReactOS CRT library
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Portable implementation of ceil
* COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#define _USE_MATH_DEFINES
#include <math.h>
#include <limits.h>
#ifdef _MSC_VER
#pragma function(ceil)
#endif
double
__cdecl
ceil(double x)
{
unsigned long long u64 = *(unsigned long long*)&x;
if ((u64 & ~(1ULL << 63)) > 0x7FF0000000000000ull)
{
u64 |= 0x0008000000000000ull;
return *(double*)&u64;
}
if ((u64 & (1ULL << 63)) == 0)
{
if (x < (double)_I64_MAX)
{
input, return it as is, otherwise add 1 */
double y = (double)(long long)x;
return (x > y) ? y + 1 : y;
}
else
{
This means the number is already an integer. */
return x;
}
}
else
{
if (x > (double)_I64_MIN)
{
x = (double)(long long)x;
return (x == 0.) ? -0.0 : x;
}
else
{
This means the number is already an integer. */
return x;
}
}
}