summaryrefslogtreecommitdiff
path: root/Libraries/LibM
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-20 13:55:57 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-10-20 17:20:20 +0200
commit570c6c8458e6bc14b08bf99be289b9bb2efd8f58 (patch)
tree952813fdd7ca738a26254281345a5db31c987c49 /Libraries/LibM
parent138abb909808747f8f3f5cbb2dcb1ecf5503a6e0 (diff)
downloadserenity-570c6c8458e6bc14b08bf99be289b9bb2efd8f58.zip
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.
Diffstat (limited to 'Libraries/LibM')
-rw-r--r--Libraries/LibM/math.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/Libraries/LibM/math.cpp b/Libraries/LibM/math.cpp
index 012d3e0ff8..51af8796ff 100644
--- a/Libraries/LibM/math.cpp
+++ b/Libraries/LibM/math.cpp
@@ -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;
}
}