Skip to content

Commit be7bd70

Browse files
hansonrhansonr
authored andcommitted
Fixes for Number.longValue()
- was using |0, but that is only for int32
1 parent 98470d3 commit be7bd70

File tree

8 files changed

+31
-8
lines changed

8 files changed

+31
-8
lines changed
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201205180144
1+
20201205191847
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201205180144
1+
20201205191847
Binary file not shown.

sources/net.sf.j2s.java.core/src/test/ScanTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public static void main(String[] args) throws Exception {
7575
closeTest();
7676
cacheTest();
7777
cacheTest2();
78-
System.err.println("Skipping Tibetan number test nonASCIITest()");
78+
System.err.println("!!!!!!!!!Skipping Tibetan number test nonASCIITest()");
7979
resetTest();
8080

8181
for (int j = 0; j < NUM_SOURCE_TYPES; j++) {
@@ -87,8 +87,8 @@ public static void main(String[] args) throws Exception {
8787
byteTest(j);
8888
shortTest(j);
8989
intTest(j);
90-
System.err.println("Skipping longTest(j)");
91-
//SwingJS does not support high-bit long numbers longTest(j);
90+
System.err.println("!!!!!!!!!!56-bit longTest(j)");
91+
longTest(j);
9292
floatTest(j);
9393
doubleTest(j);
9494
integerPatternTest(j);
@@ -1332,16 +1332,22 @@ private static void intTest(int sourceType) throws Exception {
13321332
}
13331333

13341334
private static void longTest(int sourceType) throws Exception {
1335-
Scanner s = scannerFor("022 9223372036854775807 0x8000000000000000 9223372036854775808 dog ", sourceType);
1335+
// Scanner s = scannerFor("022 9223372036854775807 0x8000000000000000 9223372036854775808 dog ", sourceType);
1336+
Scanner s = scannerFor("022 9007199254740992 -9007199254740992 9223372036854775808 dog ", sourceType);
13361337
if (!s.hasNextLong())
13371338
failed();
13381339
if (s.nextLong() != (long) 22)
13391340
failed();
13401341
if (!s.hasNextLong())
13411342
failed();
1342-
if (s.nextLong() != 9223372036854775807L)
1343+
1344+
if (s.nextLong() != 0x20000000000000L)
13431345
failed();
1344-
for (int i = 0; i < 3; i++) {
1346+
if (!s.hasNextLong())
1347+
failed();
1348+
if (s.nextLong() != -0x20000000000000L)
1349+
failed();
1350+
for (int i = 0; i < 2; i++) {
13451351
if (s.hasNextLong())
13461352
failed();
13471353
try {
@@ -1351,6 +1357,7 @@ private static void longTest(int sourceType) throws Exception {
13511357
// Correct result
13521358
}
13531359
s.next();
1360+
System.err.flush();
13541361
}
13551362
try {
13561363
s.next();

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3937,6 +3937,8 @@ Long.toHexString$J=Integer.toHexString$I;
39373937
Long.toOctalString$J=Integer.toOctalString$I;
39383938
Long.toBinaryString$J=Integer.toBinaryString$I;
39393939

3940+
m$(Long,["longValue","longValue$"],function(){return this.valueOf();});
3941+
39403942
m$(Long,"c$",
39413943
function(v){
39423944
v || v == null || (v = 0);
@@ -4315,6 +4317,9 @@ function(s){
43154317
return Clazz.new_(Float.c$$S, [s]);
43164318
}, 1);
43174319

4320+
4321+
m$(Float,["longValue$","longValue"],function(){return Math.floor(this.valueOf());});
4322+
43184323
m$(Float,"valueOf$D",
43194324
function(i){
43204325
return Clazz.new_(Float.c$$F, [i < minFloat ? -Infinity : i > maxFloat ? Infinity : i]);
@@ -4412,6 +4417,9 @@ throw Clazz.new_(NumberFormatException.c$$S, ["Not a Number : "+s]);
44124417
return v;
44134418
}, 1);
44144419

4420+
m$(Double,["longValue","longValue$"],function(){return Math.floor(this.valueOf());});
4421+
4422+
44154423
m$(Double,"valueOf$S",
44164424
function(v){
44174425
return Clazz.new_(Double.c$$S, [v]);

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17949,6 +17949,8 @@ Long.toHexString$J=Integer.toHexString$I;
1794917949
Long.toOctalString$J=Integer.toOctalString$I;
1795017950
Long.toBinaryString$J=Integer.toBinaryString$I;
1795117951

17952+
m$(Long,["longValue","longValue$"],function(){return this.valueOf();});
17953+
1795217954
m$(Long,"c$",
1795317955
function(v){
1795417956
v || v == null || (v = 0);
@@ -18327,6 +18329,9 @@ function(s){
1832718329
return Clazz.new_(Float.c$$S, [s]);
1832818330
}, 1);
1832918331

18332+
18333+
m$(Float,["longValue$","longValue"],function(){return Math.floor(this.valueOf());});
18334+
1833018335
m$(Float,"valueOf$D",
1833118336
function(i){
1833218337
return Clazz.new_(Float.c$$F, [i < minFloat ? -Infinity : i > maxFloat ? Infinity : i]);
@@ -18424,6 +18429,9 @@ throw Clazz.new_(NumberFormatException.c$$S, ["Not a Number : "+s]);
1842418429
return v;
1842518430
}, 1);
1842618431

18432+
m$(Double,["longValue","longValue$"],function(){return Math.floor(this.valueOf());});
18433+
18434+
1842718435
m$(Double,"valueOf$S",
1842818436
function(v){
1842918437
return Clazz.new_(Double.c$$S, [v]);

0 commit comments

Comments
 (0)