浏览代码

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();
 }
+
+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;
 long double nexttowardl(long double, long double) NOEXCEPT;
 
+double copysign(double x, double y);
+
 __END_DECLS