Skip to content

Commit 7a93f15

Browse files
authored
Improve StrictMath support (#10186)
Fixes #9754 Adds all missing methods as simple aliases to the respective `Math` methods, consistent with the rest of the class. Fixes a discrepancy in the return type of `Math.floorMod(long, int)`.
1 parent 834c116 commit 7a93f15

File tree

3 files changed

+108
-7
lines changed

3 files changed

+108
-7
lines changed

user/super/com/google/gwt/emul/java/lang/Math.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ public static long floorMod(long dividend, long divisor) {
150150
return ((dividend % divisor) + divisor) % divisor;
151151
}
152152

153-
public static long floorMod(long dividend, int divisor) {
154-
return floorMod(dividend, (long) divisor);
153+
public static int floorMod(long dividend, int divisor) {
154+
return (int) floorMod(dividend, (long) divisor);
155155
}
156156

157157
@SuppressWarnings("CheckStyle.MethodName")

user/super/com/google/gwt/emul/java/lang/StrictMath.java

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static double atan(double x) {
5454
}
5555

5656
public static double atan2(double y, double x) {
57-
return Math.atan(x);
57+
return Math.atan2(y, x);
5858
}
5959

6060
public static double ceil(double x) {
@@ -236,4 +236,105 @@ public static int toIntExact(long x) {
236236
public static double toRadians(double x) {
237237
return Math.toRadians(x);
238238
}
239+
240+
public static long abs(long x) {
241+
return Math.abs(x);
242+
}
243+
244+
public static int decrementExact(int x) {
245+
return Math.decrementExact(x);
246+
}
247+
248+
public static long decrementExact(long x) {
249+
return Math.decrementExact(x);
250+
}
251+
252+
public static int incrementExact(int x) {
253+
return Math.incrementExact(x);
254+
}
255+
256+
public static long incrementExact(long x) {
257+
return Math.incrementExact(x);
258+
}
259+
260+
public static long multiplyExact(long x, int y) {
261+
return Math.multiplyExact(x, y);
262+
}
263+
264+
public static long negateExact(long x) {
265+
return Math.negateExact(x);
266+
}
267+
268+
public static int negateExact(int x) {
269+
return Math.negateExact(x);
270+
}
271+
272+
public static int getExponent(float x) {
273+
return Math.getExponent(x);
274+
}
275+
276+
public static int getExponent(double x) {
277+
return Math.getExponent(x);
278+
}
279+
280+
public static int floorMod(long x, int y) {
281+
return Math.floorMod(x, y);
282+
}
283+
284+
public static double cbrt(double x) {
285+
return Math.cbrt(x);
286+
}
287+
288+
@SuppressWarnings("CheckStyle.MethodName")
289+
public static double IEEEremainder(double x, double y) {
290+
return Math.IEEEremainder(x, y);
291+
}
292+
293+
public static long floorDiv(long x, int y) {
294+
return Math.floorDiv(x, y);
295+
}
296+
297+
public static long multiplyFull(int x, int y) {
298+
return Math.multiplyFull(x, y);
299+
}
300+
301+
public static int absExact(int x) {
302+
return Math.absExact(x);
303+
}
304+
305+
public static long absExact(long x) {
306+
return Math.absExact(x);
307+
}
308+
309+
public static double ulp(double x) {
310+
return Math.ulp(x);
311+
}
312+
313+
public static float ulp(float x) {
314+
return Math.ulp(x);
315+
}
316+
317+
public static double nextAfter(double x, double direction) {
318+
return Math.nextAfter(x, direction);
319+
}
320+
321+
public static float nextAfter(float x, double direction) {
322+
return Math.nextAfter(x, direction);
323+
}
324+
325+
public static double nextUp(double x) {
326+
return Math.nextUp(x);
327+
}
328+
329+
public static float nextUp(float x) {
330+
return Math.nextUp(x);
331+
}
332+
333+
public static double nextDown(double x) {
334+
return Math.nextDown(x);
335+
}
336+
337+
public static float nextDown(float x) {
338+
return Math.nextDown(x);
339+
}
239340
}

user/test/com/google/gwt/emultest/java8/lang/MathTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ public void testFloorModLongs() {
162162
}
163163

164164
public void testFloorModLongInt() {
165-
assertEquals(0L, Math.floorMod(0L, 1L));
166-
assertEquals(1L, Math.floorMod(4L, 3L));
167-
assertEquals(0L, Math.floorMod(Long.MIN_VALUE, Integer.MIN_VALUE));
168-
assertEquals(1L, Math.floorMod(Long.MAX_VALUE, Integer.MAX_VALUE));
165+
assertEquals(0, Math.floorMod(0L, 1L));
166+
assertEquals(1, Math.floorMod(4L, 3L));
167+
assertEquals(0, Math.floorMod(Long.MIN_VALUE, Integer.MIN_VALUE));
168+
assertEquals(1, Math.floorMod(Long.MAX_VALUE, Integer.MAX_VALUE));
169169
assertThrowsArithmetic(() -> Math.floorMod(1L, 0));
170170
}
171171

0 commit comments

Comments
 (0)