lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [1/2] lucenenet git commit: detect NaN and return appropriate value
Date Sun, 19 Apr 2015 14:30:07 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/master c0aa821d4 -> c7b14909f


detect NaN and return appropriate value


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/dedfe73b
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/dedfe73b
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/dedfe73b

Branch: refs/heads/master
Commit: dedfe73be77d4779a131a01a41425ef7738ec909
Parents: c0aa821
Author: Laimonas Simutis <laimis@gmail.com>
Authored: Sat Apr 18 20:46:04 2015 -0400
Committer: Laimonas Simutis <laimis@gmail.com>
Committed: Sat Apr 18 20:46:04 2015 -0400

----------------------------------------------------------------------
 src/Lucene.Net.Core/Support/Number.cs    | 15 +++++++++++++++
 src/Lucene.Net.Core/Util/NumericUtils.cs |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/dedfe73b/src/Lucene.Net.Core/Support/Number.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Number.cs b/src/Lucene.Net.Core/Support/Number.cs
index 7b689d9..4d19e36 100644
--- a/src/Lucene.Net.Core/Support/Number.cs
+++ b/src/Lucene.Net.Core/Support/Number.cs
@@ -424,6 +424,11 @@ namespace Lucene.Net.Support
 
         public static int FloatToIntBits(float value)
         {
+            if (float.IsNaN(value))
+            {
+                return 0x7fc00000;
+            }
+
             // TODO it is claimed that this could be faster
             return BitConverter.ToInt32(BitConverter.GetBytes(value), 0);
         }
@@ -438,6 +443,16 @@ namespace Lucene.Net.Support
             return BitConverter.DoubleToInt64Bits(value);
         }
 
+        public static long DoubleToLongBits(double value)
+        {
+            if (double.IsNaN(value))
+            {
+                return 0x7ff8000000000000L;
+            }
+
+            return BitConverter.DoubleToInt64Bits(value);
+        }
+
         //Flips the endianness from Little-Endian to Big-Endian
 
         //2 bytes

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/dedfe73b/src/Lucene.Net.Core/Util/NumericUtils.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/NumericUtils.cs b/src/Lucene.Net.Core/Util/NumericUtils.cs
index a806358..f92c1cb 100644
--- a/src/Lucene.Net.Core/Util/NumericUtils.cs
+++ b/src/Lucene.Net.Core/Util/NumericUtils.cs
@@ -278,7 +278,7 @@ namespace Lucene.Net.Util
         /// <seealso cref= #sortableLongToDouble </seealso>
         public static long DoubleToSortableLong(double val)
         {
-            long f = BitConverter.DoubleToInt64Bits(val);
+            long f = Number.DoubleToLongBits(val);
             if (f < 0)
             {
                 f ^= 0x7fffffffffffffffL;


Mime
View raw message