Browse Source

LibM: Implement sqrt()

Use the x87 fsqrt instruction for that.

We cannot use __builtin_sqrt(), since GCC expands it into
a sqrt() call, so we just loop endlessly.
Sergey Bugaev 5 years ago
parent
commit
cfe8fdd5aa
1 changed files with 4 additions and 2 deletions
  1. 4 2
      Libraries/LibM/math.cpp

+ 4 - 2
Libraries/LibM/math.cpp

@@ -58,9 +58,11 @@ double tan(double angle)
     return ampsin(angle) / ampsin(M_PI_2 + angle);
 }
 
-double sqrt(double)
+double sqrt(double x)
 {
-    ASSERT_NOT_REACHED();
+    double res;
+    __asm__("fsqrt" : "=t"(res) : "0"(x));
+    return res;
 }
 
 double sinh(double)