Skip to content

Commit fb169e3

Browse files
committed
// BH 2023.01.22 fix for Double.doubleToRawLongBits missing and
Float.floatToIntBits failing on NaN
1 parent c66f0dd commit fb169e3

File tree

8 files changed

+18
-15
lines changed

8 files changed

+18
-15
lines changed
373 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20230112135435
1+
20230119124749
373 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20230112135435
1+
20230119124749
90 Bytes
Binary file not shown.

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@ public static void main(String[] args) {
2828
System.out.println(d == Double.valueOf(0));
2929
System.out.println(d1 == Double.valueOf(-0));
3030
System.out.println(d1 == Double.valueOf(-0));
31-
31+
System.out.println(Long.toHexString(Double.doubleToLongBits(Double.NaN)));
32+
System.out.println(Long.toHexString(Double.doubleToRawLongBits(Double.NaN)));
33+
System.out.println(Long.toHexString(Double.doubleToLongBits(-0d)));
34+
System.out.println(Long.toHexString(Double.doubleToRawLongBits(-0d)));
35+
System.out.println(Integer.toHexString(Float.floatToRawIntBits(Float.NaN)));
36+
System.out.println(Integer.toHexString(Float.floatToIntBits(Float.NaN)));
37+
System.out.println(Integer.toHexString(Float.floatToRawIntBits(-0f)));
38+
System.out.println(Integer.toHexString(Float.floatToIntBits(-0f)));
3239

3340

3441
assert(("" + Double.valueOf(-0)).equals("0.0"));

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10+
// BH 2023.01.22 fix for Double.doubleToRawLongBits missing and Float.floatToIntBits failing on NaN
1011
// BH 2023.01.15 fix for int[2][3][] not initializing properly
1112
// BH 2022.12.03 fix for Double.isInfinite should not be true for NaN
1213
// BH 2022.12.03 fix for Double.parseDouble("") and new Double(NaN) should be NaN, not 0
@@ -1278,7 +1279,7 @@ var newTypedA = function(baseClass, args, nBits, ndims, isClone) {
12781279
var arr = new Int32Array(dim);
12791280
break;
12801281
case 64:
1281-
var arr = (paramType != "JA" ? new Float64Array(dim) : typeof dim == "number" ? new Array(dim) : dim);
1282+
var arr = (paramType != "JA" ? new Float64Array(dim) : typeof dim == "number" ? new Array(dim).fill(0) : dim);
12821283
break;
12831284
default:
12841285
nBits = 0;
@@ -1288,8 +1289,7 @@ var newTypedA = function(baseClass, args, nBits, ndims, isClone) {
12881289
} else {
12891290
arr = (dim < 0 ? val : new Array(dim));
12901291
if (dim > 0 && val != null)
1291-
for (var i = dim; --i >= 0;)
1292-
arr[i] = val;
1292+
arr.fill(val);
12931293
}
12941294
break;
12951295
}
@@ -5394,8 +5394,6 @@ geta64 = function() {
53945394
}
53955395

53965396
Float.floatToIntBits$F = function(f) {
5397-
if (isNaN(f))
5398-
return
53995397
return Float.floatToRawIntBits$F(f);
54005398
}
54015399

@@ -5541,7 +5539,7 @@ throw Clazz.new_(NumberFormatException.c$$S, ["Not a Number : "+s]);
55415539
return v;
55425540
}, 1);
55435541

5544-
m$(Double,"doubleToLongBits$D",
5542+
m$(Double,["doubleToRawLongBits$D", "doubleToLongBits$D"],
55455543
function(d){
55465544
geta64()[0] = d;
55475545
return toLongI2(i64[0], i64[1]);

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14046,6 +14046,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
1404614046

1404714047
// Google closure compiler cannot handle Clazz.new or Clazz.super
1404814048

14049+
// BH 2023.01.22 fix for Double.doubleToRawLongBits missing and Float.floatToIntBits failing on NaN
1404914050
// BH 2023.01.15 fix for int[2][3][] not initializing properly
1405014051
// BH 2022.12.03 fix for Double.isInfinite should not be true for NaN
1405114052
// BH 2022.12.03 fix for Double.parseDouble("") and new Double(NaN) should be NaN, not 0
@@ -15317,7 +15318,7 @@ var newTypedA = function(baseClass, args, nBits, ndims, isClone) {
1531715318
var arr = new Int32Array(dim);
1531815319
break;
1531915320
case 64:
15320-
var arr = (paramType != "JA" ? new Float64Array(dim) : typeof dim == "number" ? new Array(dim) : dim);
15321+
var arr = (paramType != "JA" ? new Float64Array(dim) : typeof dim == "number" ? new Array(dim).fill(0) : dim);
1532115322
break;
1532215323
default:
1532315324
nBits = 0;
@@ -15327,8 +15328,7 @@ var newTypedA = function(baseClass, args, nBits, ndims, isClone) {
1532715328
} else {
1532815329
arr = (dim < 0 ? val : new Array(dim));
1532915330
if (dim > 0 && val != null)
15330-
for (var i = dim; --i >= 0;)
15331-
arr[i] = val;
15331+
arr.fill(val);
1533215332
}
1533315333
break;
1533415334
}
@@ -19433,8 +19433,6 @@ geta64 = function() {
1943319433
}
1943419434

1943519435
Float.floatToIntBits$F = function(f) {
19436-
if (isNaN(f))
19437-
return
1943819436
return Float.floatToRawIntBits$F(f);
1943919437
}
1944019438

@@ -19580,7 +19578,7 @@ throw Clazz.new_(NumberFormatException.c$$S, ["Not a Number : "+s]);
1958019578
return v;
1958119579
}, 1);
1958219580

19583-
m$(Double,"doubleToLongBits$D",
19581+
m$(Double,["doubleToRawLongBits$D", "doubleToLongBits$D"],
1958419582
function(d){
1958519583
geta64()[0] = d;
1958619584
return toLongI2(i64[0], i64[1]);

0 commit comments

Comments
 (0)