You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/09/17 21:23:25 UTC

svn commit: r1703672 - in /poi/trunk/src: java/org/apache/poi/ss/formula/functions/Dec2Hex.java testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java

Author: centic
Date: Thu Sep 17 19:23:25 2015
New Revision: 1703672

URL: http://svn.apache.org/viewvc?rev=1703672&view=rev
Log:
Bug 57915: Fix Dev2Hex for numbers larger than Integer.MAX_VALUE and less than Integer.MIN_VALUE

Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java
    poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java?rev=1703672&r1=1703671&r2=1703672&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java Thu Sep 17 19:23:25 2015
@@ -112,7 +112,7 @@ public final class Dec2Hex extends Var1o
             hex = String.format(Locale.ROOT, "%0"+placesNumber+"X", number1.intValue());
         }
         else {
-            hex = Integer.toHexString(number1.intValue());
+            hex = Long.toHexString(number1.longValue());
         }
 
         if (number1 < 0) {

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java?rev=1703672&r1=1703671&r2=1703672&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDec2Hex.java Thu Sep 17 19:23:25 2015
@@ -81,6 +81,28 @@ public final class TestDec2Hex extends T
 
 		confirmValue("Converts decimal -54 to hexadecimal, 2 is ignored","-54", "2",  "FFFFFFFFCA");
 		confirmValue("places is optionnal","-54", "FFFFFFFFCA");
+		
+		confirmValue("Converts normal decimal number to hexadecimal", "100", "64");
+        
+		String maxInt = Integer.toString(Integer.MAX_VALUE);
+        assertEquals("2147483647", maxInt);
+        confirmValue("Converts INT_MAX to hexadecimal", maxInt, "7FFFFFFF");
+
+        String minInt = Integer.toString(Integer.MIN_VALUE);
+        assertEquals("-2147483648", minInt);
+        confirmValue("Converts INT_MIN to hexadecimal", minInt, "FF80000000");
+
+        String maxIntPlusOne = Long.toString(((long)Integer.MAX_VALUE)+1);
+        assertEquals("2147483648", maxIntPlusOne);
+        confirmValue("Converts INT_MAX + 1 to hexadecimal", maxIntPlusOne, "80000000");
+        
+        String maxLong = Long.toString(549755813887l);
+        assertEquals("549755813887", maxLong);
+        confirmValue("Converts the max supported value to hexadecimal", maxLong, "7FFFFFFFFF");
+        
+        String minLong = Long.toString(-549755813888l);
+        assertEquals("-549755813888", minLong);
+        confirmValue("Converts the min supported value to hexadecimal", minLong, "FF80000000");
 	}
 
     public void testErrors() {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org