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