Add Math.floorMod and Math.floorDiv (#544)

This commit is contained in:
Ivan Hetman 2020-11-23 10:49:33 +02:00 committed by GitHub
parent bec0f44869
commit 98f5c5da73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -127,6 +127,32 @@ public final class TMath extends TObject {
return (long) (a + signum(a) * 0.5); return (long) (a + signum(a) * 0.5);
} }
public static int floorDiv(int a, int b) {
int div = a / b;
return (a ^ b) < 0 && div * b != a ? div - 1 : div;
}
public static long floorDiv(long a, int b) {
return floorDiv(a, (long) b);
}
public static long floorDiv(long a, long b) {
long div = a / b;
return (a ^ b) < 0 && div * b != a ? div - 1 : div;
}
public static int floorMod(int a, int b) {
return a - floorDiv(a, b) * b;
}
public static int floorMod(long a, int b) {
return (int) (a - floorDiv(a, b) * b);
}
public static long floorMod(long a, long b) {
return a - floorDiv(a, b) * b;
}
@Unmanaged @Unmanaged
public static double random() { public static double random() {
return PlatformDetector.isC() ? randomC() : randomImpl(); return PlatformDetector.isC() ? randomC() : randomImpl();