mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: add methods/fields from JDK 21 to Math (#784)
This commit is contained in:
parent
7e761ca7e9
commit
a493d003e5
|
@ -27,6 +27,7 @@ import org.teavm.interop.Unmanaged;
|
|||
public final class TMath extends TObject {
|
||||
public static final double E = 2.71828182845904523536;
|
||||
public static final double PI = 3.14159265358979323846;
|
||||
public static final double TAU = 2 * PI;
|
||||
|
||||
private TMath() {
|
||||
}
|
||||
|
@ -516,4 +517,32 @@ public final class TMath extends TObject {
|
|||
}
|
||||
return TFloat.intBitsToFloat(bits);
|
||||
}
|
||||
|
||||
public static int clamp(long value, int min, int max) {
|
||||
if (min > max) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return (int) Math.min(max, Math.max(value, min));
|
||||
}
|
||||
|
||||
public static long clamp(long value, long min, long max) {
|
||||
if (min > max) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return Math.min(max, Math.max(value, min));
|
||||
}
|
||||
|
||||
public static double clamp(double value, double min, double max) {
|
||||
if (!(min < max) && (Double.isNaN(min) || Double.isNaN(max) || Double.compare(min, max) > 0)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return Math.min(max, Math.max(value, min));
|
||||
}
|
||||
|
||||
public static float clamp(float value, float min, float max) {
|
||||
if (!(min < max) && (Float.isNaN(min) || Float.isNaN(max) || Float.compare(min, max) > 0)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return Math.min(max, Math.max(value, min));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.teavm.classlib.java.lang;
|
|||
public final class TStrictMath extends TObject {
|
||||
public static final double E = 2.71828182845904523536;
|
||||
public static final double PI = 3.14159265358979323846;
|
||||
public static final double TAU = 2 * PI;
|
||||
|
||||
private TStrictMath() {
|
||||
}
|
||||
|
@ -229,4 +230,20 @@ public final class TStrictMath extends TObject {
|
|||
public static float nextUp(float f) {
|
||||
return TMath.nextUp(f);
|
||||
}
|
||||
|
||||
public static int clamp(long value, int min, int max) {
|
||||
return TMath.clamp(value, min, max);
|
||||
}
|
||||
|
||||
public static long clamp(long value, long min, long max) {
|
||||
return TMath.clamp(value, min, max);
|
||||
}
|
||||
|
||||
public static double clamp(double value, double min, double max) {
|
||||
return TMath.clamp(value, min, max);
|
||||
}
|
||||
|
||||
public static float clamp(float value, float min, float max) {
|
||||
return TMath.clamp(value, min, max);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user