Parcourir la source

done double constructor

jezv il y a 11 mois
Parent
commit
5825357de3
1 fichiers modifiés avec 10 ajouts et 0 suppressions
  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;
     const unsigned long long int mantisBits = bits & 0xFFFFFFFFFFFFF;
     unsigned long long int significant = (long long int)pow(2, 52) | mantisBits;
     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 sign = signBit ? -1 : 1;
     const long long int exp = exponentBits - 1023 - 52;
     const long long int exp = exponentBits - 1023 - 52;