diff --git a/src/java/org/apache/poi/util/LittleEndian.java b/src/java/org/apache/poi/util/LittleEndian.java index 935fd5a668..d7cdc18426 100644 --- a/src/java/org/apache/poi/util/LittleEndian.java +++ b/src/java/org/apache/poi/util/LittleEndian.java @@ -386,7 +386,11 @@ public class LittleEndian public static void putDouble(final byte[] data, final int offset, final double value) { - putNumber(data, offset, Double.doubleToRawLongBits(value), DOUBLE_SIZE); + // Excel likes NaN to be a specific value. + if (Double.isNaN(value)) + putNumber(data, offset, -276939487313920L, DOUBLE_SIZE); + else + putNumber(data, offset, Double.doubleToLongBits(value), DOUBLE_SIZE); } diff --git a/src/testcases/org/apache/poi/util/TestLittleEndian.java b/src/testcases/org/apache/poi/util/TestLittleEndian.java index 56d830cc0e..406737bdb2 100644 --- a/src/testcases/org/apache/poi/util/TestLittleEndian.java +++ b/src/testcases/org/apache/poi/util/TestLittleEndian.java @@ -166,9 +166,6 @@ public class TestLittleEndian assertEquals(_doubles[ 1 ], LittleEndian.getDouble( _double_array, LittleEndian.DOUBLE_SIZE), 0.000001); assertTrue(Double.isNaN(LittleEndian.getDouble(_nan_double_array))); - // does not work. apparently nan does not always equal nan! - //assertEquals(_doubles[ 2 ], LittleEndian.getDouble(_nan_double_array), 0.000001); - double nan = LittleEndian.getDouble(_nan_double_array); byte[] data = new byte[8]; LittleEndian.putDouble(data, nan);