summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-03-05 20:46:25 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-05 20:46:25 +0100
commit9f8a9dba0b55fc8c17b9732c660e87bb042cb78b (patch)
tree62afa8708177ec3727cd19e209ccedf4aa4b2f83 /Userland/Libraries
parentfc5b252010aeb6155d22e752914b8b9e371c5398 (diff)
downloadserenity-9f8a9dba0b55fc8c17b9732c660e87bb042cb78b.zip
LibM: Add naive implementation of copysign()
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibM/math.cpp11
-rw-r--r--Userland/Libraries/LibM/math.h2
2 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibM/math.cpp b/Userland/Libraries/LibM/math.cpp
index a17666af81..115e5f5200 100644
--- a/Userland/Libraries/LibM/math.cpp
+++ b/Userland/Libraries/LibM/math.cpp
@@ -742,4 +742,15 @@ long double nexttowardl(long double, long double) NOEXCEPT
{
TODO();
}
+
+double copysign(double x, double y)
+{
+ if (x < 0 && y < 0)
+ return x;
+ if (x >= 0 && y < 0)
+ return -x;
+ if (x < 0 && y >= 0)
+ return -x;
+ return x;
+}
}
diff --git a/Userland/Libraries/LibM/math.h b/Userland/Libraries/LibM/math.h
index a13acd8355..02e7c1f7a4 100644
--- a/Userland/Libraries/LibM/math.h
+++ b/Userland/Libraries/LibM/math.h
@@ -143,4 +143,6 @@ double nexttoward(double, long double) NOEXCEPT;
float nexttowardf(float, long double) NOEXCEPT;
long double nexttowardl(long double, long double) NOEXCEPT;
+double copysign(double x, double y);
+
__END_DECLS