Ver código fonte

LibM: Add INFINITY macro

Linus Groh 5 anos atrás
pai
commit
ead76377b0

+ 4 - 4
Libraries/LibJS/Runtime/Value.h

@@ -76,8 +76,8 @@ public:
     bool is_infinity() const { return is_number() && __builtin_isinf(as_double()); }
     bool is_positive_infinity() const { return is_number() && __builtin_isinf_sign(as_double()) > 0; }
     bool is_negative_infinity() const { return is_number() && __builtin_isinf_sign(as_double()) < 0; }
-    bool is_positive_zero() const { return is_number() && 1.0 / as_double() == __builtin_huge_val(); }
-    bool is_negative_zero() const { return is_number() && 1.0 / as_double() == -__builtin_huge_val(); }
+    bool is_positive_zero() const { return is_number() && 1.0 / as_double() == INFINITY; }
+    bool is_negative_zero() const { return is_number() && 1.0 / as_double() == -INFINITY; }
     bool is_integer() const { return is_finite_number() && (i32)as_double() == as_double(); }
     bool is_finite_number() const
     {
@@ -257,12 +257,12 @@ inline Value js_nan()
 
 inline Value js_infinity()
 {
-    return Value(__builtin_huge_val());
+    return Value(INFINITY);
 }
 
 inline Value js_negative_infinity()
 {
-    return Value(-__builtin_huge_val());
+    return Value(-INFINITY);
 }
 
 Value greater_than(Interpreter&, Value lhs, Value rhs);

+ 2 - 2
Libraries/LibM/math.cpp

@@ -213,7 +213,7 @@ double log(double x)
     if (x < 0)
         return NAN;
     if (x == 0)
-        return -__builtin_huge_val();
+        return -INFINITY;
     double y = 1 + 2 * (x - 1) / (x + 1);
     double exponentiated = exp(y);
     y = y + 2 * (x - exponentiated) / (x + exponentiated);
@@ -257,7 +257,7 @@ double exp(double exponent)
             if (integer_part & 32)
                 result *= e_to_power<32>();
             if (integer_part >= 64)
-                return __builtin_huge_val();
+                return INFINITY;
         }
         exponent -= integer_part;
     } else if (exponent < 0)

+ 1 - 0
Libraries/LibM/math.h

@@ -31,6 +31,7 @@
 __BEGIN_DECLS
 
 #define HUGE_VAL 1e10000
+#define INFINITY __builtin_huge_val()
 #define NAN __builtin_nan("")
 #define M_E 2.718281828459045
 #define M_PI 3.141592653589793