mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +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
Notes:
sideshowbarker
2024-07-19 07:51:07 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/c7b4b5fe001 Pull-request: https://github.com/SerenityOS/serenity/pull/1667
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
Reference in a new issue