Skip to content

Commit a94c206

Browse files
hansonrhansonr
authored andcommitted
Java 9/10 updates, including Math.floorMod
1 parent d7178ed commit a94c206

File tree

7 files changed

+119
-2
lines changed

7 files changed

+119
-2
lines changed
431 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20201120120959
1+
20201120135241
878 Bytes
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200910065611
1+
20201120135241
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package test;
2+
3+
import java.util.ImmutableCollections;
4+
5+
/**
6+
* A class with a main method entry point for ad hoc tests of JalviewJS
7+
* behaviour. The J2S transpiler should generate an html entry point for this
8+
* class, allowing comparison between Java and Javascript execution.
9+
*/
10+
public class Test_List extends Test_ {
11+
12+
public static void main(String[] args) {
13+
14+
java.util.List<Integer> li = of(1,2,3,4);
15+
System.out.println(li);
16+
17+
}
18+
19+
static <E> java.util.List<E> of(E e1, E e2, E e3, E e4) {
20+
Object o = new Object[] {1,2,3};
21+
return new ImmutableCollections.ListN<>(e1, e2, e3, e4);
22+
}
23+
//
24+
// // Java 9 and 10 additions
25+
//
26+
// static <E> List<E> of() {
27+
// return ImmutableCollections.emptyList();
28+
// }
29+
//
30+
// static <E> List<E> of(E e1, E e2) {
31+
// return new ImmutableCollections.List12<>(e1, e2);
32+
// }
33+
//
34+
//
35+
// static <E> List<E> of(E... elements) {
36+
// switch (elements.length) { // implicit null check of elements
37+
// case 0:
38+
// return ImmutableCollections.emptyList();
39+
// case 1:
40+
// return new ImmutableCollections.List12<>(elements[0]);
41+
// case 2:
42+
// return new ImmutableCollections.List12<>(elements[0], elements[1]);
43+
// default:
44+
// return new ImmutableCollections.ListN<>(elements);
45+
// }
46+
// }
47+
//
48+
// static <E> List<E> copyOf(Collection<? extends E> coll) {
49+
// return ImmutableCollections.listCopy(coll);
50+
// }
51+
//
52+
//
53+
}

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3411,6 +3411,70 @@ Math.rint || (Math.rint = function(a) {
34113411
return Math.round(a) + ((b = a % 1) != 0.5 && b != -0.5 ? 0 : (b = Math.round(a % 2)) > 0 ? b - 2 : b);
34123412
});
34133413

3414+
// Java 1.8
3415+
3416+
Math.addExact = function(x, y) {
3417+
var r = x + y;
3418+
// HD 2-12 Overflow iff both arguments have the opposite sign of the result
3419+
if (((x ^ r) & (y ^ r)) < 0) {
3420+
throw new ArithmeticException("integer overflow");
3421+
}
3422+
return r;
3423+
}
3424+
3425+
3426+
Math.subtractExact = function(x, y) {
3427+
var r = x - y;
3428+
// HD 2-12 Overflow iff the arguments have different signs and
3429+
// the sign of the result is different than the sign of x
3430+
if (((x ^ y) & (x ^ r)) < 0) {
3431+
throw new ArithmeticException("integer overflow");
3432+
}
3433+
return r;
3434+
}
3435+
3436+
Math.multiplyExact = function(x, y) {
3437+
var r = x * y;
3438+
if ((r | 0) != r) {
3439+
throw new ArithmeticException("integer overflow");
3440+
}
3441+
return r;
3442+
}
3443+
Math.incrementExact = function(a) {
3444+
if (a == Integer.MAX_VALUE) {
3445+
throw new ArithmeticException("integer overflow");
3446+
}
3447+
return a + 1;
3448+
}
3449+
3450+
Math.decrementExact = function(a) {
3451+
if (a == Integer.MIN_VALUE) {
3452+
throw new ArithmeticException("integer overflow");
3453+
}
3454+
return a - 1;
3455+
}
3456+
3457+
Math.negateExact = function(a) {return -a}
3458+
3459+
Math.toIntExact = function(value) {
3460+
if ((value | 0) != value) {
3461+
throw new ArithmeticException("integer overflow");
3462+
}
3463+
return value;
3464+
}
3465+
Math.toIntExact = function(a) { return a}
3466+
3467+
Math.floorDiv || (Math.floorDiv = function(x,y) {
3468+
var r = (x / y) | 0;
3469+
if ((x ^ y) < 0 && (r * y != x)) {
3470+
r--;
3471+
}
3472+
return r;
3473+
})
3474+
3475+
Math.floorMod || (Math.floorMod = function(x,y) { return x - Math.floorDiv(x, y) * y; })
3476+
3477+
//
34143478
Math.log10||(Math.log10=function(a){return Math.log(a)/Math.E});
34153479

34163480
Math.hypot||(Math.hypot=function(x,y){return Math.sqrt(Math.pow(x,2)+Math.pow(y,2))});

0 commit comments

Comments
 (0)