1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 01:05:08 +00:00

LibM: Make roundf() and ceilf() slightly less terrible

These implementations still don't handle all of the corner cases that
are possible, but at least they are somewhat usable now.
This commit is contained in:
Andreas Kling 2019-10-20 13:55:57 +02:00
parent 138abb9098
commit 570c6c8458

View file

@ -276,14 +276,20 @@ long double frexpl(long double, int*)
float roundf(float value)
{
// FIXME: Please fix me. I am sad.
return (int)value;
// FIXME: Please fix me. I am naive.
if (value >= 0.0f)
return (float)(int)(value + 0.5f);
return (float)(int)(value - 0.5f);
}
float ceilf(float value)
{
// FIXME: Please fix me. I am sad.
return (int)value;
// FIXME: Please fix me. I am naive.
int as_int = (int)value;
if (value == (float)as_int) {
return (float)as_int;
}
return as_int + 1;
}
}