mirror of
https://github.com/RGBCube/serenity
synced 2025-07-07 20:17:34 +00:00
LibM: Fix ceil() and ceilf() for negative numbers
These functions are using a naive approach: casting double/float to int and returning the result + 1. That increment by one must only happen for positive input values though.
This commit is contained in:
parent
7cda0b9027
commit
c7b4b5fe00
1 changed files with 12 additions and 4 deletions
|
@ -384,8 +384,12 @@ float ceilf(float value)
|
|||
{
|
||||
// FIXME: Please fix me. I am naive.
|
||||
int as_int = (int)value;
|
||||
if (value == (float)as_int) {
|
||||
return (float)as_int;
|
||||
if (value == (float)as_int)
|
||||
return as_int;
|
||||
if (value < 0) {
|
||||
if (as_int == 0)
|
||||
return -0;
|
||||
return as_int;
|
||||
}
|
||||
return as_int + 1;
|
||||
}
|
||||
|
@ -394,8 +398,12 @@ double ceil(double value)
|
|||
{
|
||||
// FIXME: Please fix me. I am naive.
|
||||
int as_int = (int)value;
|
||||
if (value == (double)as_int) {
|
||||
return (double)as_int;
|
||||
if (value == (double)as_int)
|
||||
return as_int;
|
||||
if (value < 0) {
|
||||
if (as_int == 0)
|
||||
return -0;
|
||||
return as_int;
|
||||
}
|
||||
return as_int + 1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue