John Marsden avatar John Marsden committed 03e8311

Reduce the size of number that will use long. At very large numbers longs can be wrong (apparently) so I will push these guys into a Big variant.

Comments (0)

Files changed (2)

src/main/java/cc/plural/jsonij/JSONParser.java

         JSON.Numeric value = null;
         StringBuilder numericStringBuilder = new StringBuilder();
         @SuppressWarnings("unused")
-		boolean minusFlag = false;
+	boolean minusFlag = false;
         boolean decimalFlag = false;
         boolean exponetFlag = false;
         int beforeDecimalCount = 0;
             }
         }
         if (!decimalFlag && !exponetFlag) {
-            if (beforeDecimalCount < 18) {
+            if (beforeDecimalCount < 16) {
                 value = new JSON.Numeric(Long.parseLong(numericStringBuilder.toString()));
             } else {
                 value = new JSON.Numeric(new BigInteger(numericStringBuilder.toString()));
             }
         } else {
-            if (beforeDecimalCount + afterDecimalCount < 18) {
+            if (beforeDecimalCount + afterDecimalCount < 16) {
                 value = new JSON.Numeric(Double.parseDouble(numericStringBuilder.toString()));
             } else {
                 value = new JSON.Numeric(new BigDecimal(numericStringBuilder.toString()));

src/test/java/jsonij/legacy/SJTest.java

     }
 
     @Test
-    public void testSupportDoublePrecisionFloatingPoint() throws ParserException, IOException {
-        System.out.println("Double precision floating point");
+    public void testSupportDoublePrecisionPostiveFloatingPoint() throws ParserException, IOException {
+        System.out.println("Double precision postive floating point");
         String testInput = "{ \"v\":1.7976931348623157E308}";
-        String testSoultion = "{\"v\":1.7976931348623157E308}";
+        String testSoultion = "{\"v\":1.7976931348623157E+308}";
         JSON json = JSON.parse(testInput);
         String testOutput = json.toJSON();
         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
         System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
         assertEquals(testSoultion, testOutput);
     }
+    
+    
+    @Test
+    public void testSupportDoublePrecisionNegativeFloatingPoint() throws ParserException, IOException {
+        System.out.println("Double precision negative floating point");
+        String testInput = "{ \"v\":-9.87654321921234567E-200}";
+        String testSoultion = "{\"v\":-9.87654321921234567E-200}";
+        JSON json = JSON.parse(testInput);
+        String testOutput = json.toJSON();
+        System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
+        assertEquals(testSoultion, testOutput);
+        testInput = "{   \t \"v\"  \t :  -9.87654321921234567E-200  }";
+        json = JSON.parse(testInput);
+        testOutput = json.toJSON();
+        System.out.println(String.format("\tInput: %s\r\n\tOutput: %s", testInput, testOutput));
+        assertEquals(testSoultion, testOutput);
+    }
 
     @Test
     public void testUnicode() throws ParserException, IOException {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.