Преглед на файлове

LibM: Add naive implementation of copysign()

Andreas Kling преди 4 години
родител
ревизия
9f8a9dba0b
променени са 2 файла, в които са добавени 13 реда и са изтрити 0 реда
  1. 11 0
      Userland/Libraries/LibM/math.cpp
  2. 2 0
      Userland/Libraries/LibM/math.h

+ 11 - 0
Userland/Libraries/LibM/math.cpp

@@ -742,4 +742,15 @@ long double nexttowardl(long double, long double) NOEXCEPT
 {
 {
     TODO();
     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;
+}
 }
 }

+ 2 - 0
Userland/Libraries/LibM/math.h

@@ -143,4 +143,6 @@ double nexttoward(double, long double) NOEXCEPT;
 float nexttowardf(float, long double) NOEXCEPT;
 float nexttowardf(float, long double) NOEXCEPT;
 long double nexttowardl(long double, long double) NOEXCEPT;
 long double nexttowardl(long double, long double) NOEXCEPT;
 
 
+double copysign(double x, double y);
+
 __END_DECLS
 __END_DECLS