Bladeren bron

Merge pull request #3309 from mahiuchun/const

Improve ToBinary() for double precision.
Kim Kulling 5 jaren geleden
bovenliggende
commit
95a23af16f
1 gewijzigde bestanden met toevoegingen van 4 en 3 verwijderingen
  1. 4 3
      code/Common/SpatialSort.cpp

+ 4 - 3
code/Common/SpatialSort.cpp

@@ -208,13 +208,14 @@ BinFloat ToBinary(const ai_real &pValue) {
     // floating-point numbers are of sign-magnitude format, so find out what signed number
     //  representation we must convert negative values to.
     // See http://en.wikipedia.org/wiki/Signed_number_representations.
+    const BinFloat mask = BinFloat(1) << (CHAR_BIT * sizeof(BinFloat) - 1);
 
     // Two's complement?
-    const bool DefaultValue = ((-42 == (~42 + 1)) && (binValue & 0x80000000));
-    const bool OneComplement = ((-42 == ~42) && (binValue & 0x80000000));
+    const bool DefaultValue = ((-42 == (~42 + 1)) && (binValue & mask));
+    const bool OneComplement = ((-42 == ~42) && (binValue & mask));
 
     if (DefaultValue)
-        return BinFloat(BinFloat(1) << (CHAR_BIT * sizeof(BinFloat) - 1)) - binValue;
+        return mask - binValue;
     // One's complement?
     else if (OneComplement)
         return BinFloat(-0) - binValue;