Explorar o código

done double constructor

jezv hai 1 ano
pai
achega
5825357de3
Modificáronse 1 ficheiros con 10 adicións e 0 borrados
  1. 10 0
      Rational.cpp

+ 10 - 0
Rational.cpp

@@ -45,6 +45,16 @@ Rational::Rational(double x)
     const unsigned long long int mantisBits = bits & 0xFFFFFFFFFFFFF;
     unsigned long long int significant = (long long int)pow(2, 52) | mantisBits;
 
+    if (exponentBits == 0 and mantisBits == 0)
+    {
+        num = 0;
+        denum = 1;
+    }
+    else if(exponentBits == 2046)
+    {
+        throw "Rational doesn't support NaN or Inf";
+    }
+
     const long long int sign = signBit ? -1 : 1;
     const long long int exp = exponentBits - 1023 - 52;