From b274120b3c6c827cf58e8f9315b1b2f43dd70c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mi=C8=9Bca=20Dumitru?= Date: Sun, 7 Mar 2021 23:14:46 +0200 Subject: [PATCH] LibM: Implement copysign for float and long double --- Userland/Libraries/LibM/math.cpp | 30 +++++++++++++++++++++++------- Userland/Libraries/LibM/math.h | 4 +++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibM/math.cpp b/Userland/Libraries/LibM/math.cpp index 46e506d138..da0e6d3c11 100644 --- a/Userland/Libraries/LibM/math.cpp +++ b/Userland/Libraries/LibM/math.cpp @@ -289,6 +289,17 @@ static FloatT internal_scalbn(FloatT x, int exponent) NOEXCEPT return extractor.d; } +template +static FloatT internal_copysign(FloatT x, FloatT y) NOEXCEPT +{ + using Extractor = FloatExtractor; + Extractor ex, ey; + ex.d = x; + ey.d = y; + ex.sign = ey.sign; + return ex.d; +} + extern "C" { double trunc(double x) NOEXCEPT @@ -845,14 +856,19 @@ long double nexttowardl(long double, long double) NOEXCEPT TODO(); } -double copysign(double x, double y) +float copysignf(float x, float y) NOEXCEPT { - using Extractor = FloatExtractor; - Extractor ex, ey; - ex.d = x; - ey.d = y; - ex.sign = ey.sign; - return ex.d; + return internal_copysign(x, y); +} + +double copysign(double x, double y) NOEXCEPT +{ + return internal_copysign(x, y); +} + +long double copysignl(long double x, long double y) NOEXCEPT +{ + return internal_copysign(x, y); } float scalbnf(float x, int exponent) NOEXCEPT diff --git a/Userland/Libraries/LibM/math.h b/Userland/Libraries/LibM/math.h index a0019cbdc3..db6b7373d9 100644 --- a/Userland/Libraries/LibM/math.h +++ b/Userland/Libraries/LibM/math.h @@ -170,6 +170,8 @@ float scalbnlf(float, long) NOEXCEPT; double scalbln(double, long) NOEXCEPT; long double scalblnl(long double, long) NOEXCEPT; -double copysign(double x, double y); +float copysignf(float x, float y) NOEXCEPT; +double copysign(double x, double y) NOEXCEPT; +long double copysignl(long double x, long double y) NOEXCEPT; __END_DECLS