8030200: Wrong result for Number.prototype.toString() for certain radix/inputs
authorhannesw
Mon, 14 Apr 2014 17:45:05 +0200
changeset 23948 f4b2c2cd63ad
parent 23947 36ce4a262b4a
child 23949 22b52f78c693
8030200: Wrong result for Number.prototype.toString() for certain radix/inputs Reviewed-by: sundar, jlaskey, lagergren
nashorn/src/jdk/nashorn/internal/runtime/JSType.java
nashorn/test/script/basic/JDK-8030200.js
nashorn/test/script/basic/JDK-8030200.js.EXPECTED
nashorn/test/script/basic/NASHORN-173.js.EXPECTED
--- a/nashorn/src/jdk/nashorn/internal/runtime/JSType.java	Mon Apr 14 17:43:38 2014 +0200
+++ b/nashorn/src/jdk/nashorn/internal/runtime/JSType.java	Mon Apr 14 17:45:05 2014 +0200
@@ -438,7 +438,9 @@
 
         // encode integer part from least significant digit, then reverse
         do {
-            sb.append(chars.charAt((int) (intPart % radix)));
+            final double remainder = intPart % radix;
+            sb.append(chars.charAt((int) remainder));
+            intPart -= remainder;
             intPart /= radix;
         } while (intPart >= 1.0);
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8030200.js	Mon Apr 14 17:45:05 2014 +0200
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8030200: Wrong result for Number.prototype.toString() for certain radix/inputs
+ *
+ * @test
+ * @run
+ */
+
+var n = 0x8000000000000800;
+print(n);
+var s = n.toString(5);
+var m = parseInt(s, 5);
+print(m === n);
+print(n);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8030200.js.EXPECTED	Mon Apr 14 17:45:05 2014 +0200
@@ -0,0 +1,3 @@
+9223372036854778000
+true
+9223372036854778000
--- a/nashorn/test/script/basic/NASHORN-173.js.EXPECTED	Mon Apr 14 17:43:38 2014 +0200
+++ b/nashorn/test/script/basic/NASHORN-173.js.EXPECTED	Mon Apr 14 17:45:05 2014 +0200
@@ -132,7 +132,7 @@
 2.3423446609034533e+21
 2.3423446609034533e+21
 11111101111101010001111111010101101000101011011001001000000000000000000
-2224143002343343220233144213324
+2224143002343343220233044213324
 375752177255053311000000
 73b92b9962990aa44400
 7efa8fead15b240000