mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-08-31 22:22:49 +00:00
Add isFinite util methods.
This commit is contained in:
parent
fb96a1afa9
commit
2b22e68f5a
1 changed files with 10 additions and 2 deletions
|
@ -102,14 +102,22 @@ public final class NumberConversions {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isFinite(double d) {
|
||||||
|
return Math.abs(d) <= Double.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFinite(float f) {
|
||||||
|
return Math.abs(f) <= Float.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
public static void checkFinite(double d, String message) {
|
public static void checkFinite(double d, String message) {
|
||||||
if (Double.isNaN(d) || Double.isInfinite(d)) {
|
if (!isFinite(d)) {
|
||||||
throw new IllegalArgumentException(message);
|
throw new IllegalArgumentException(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkFinite(float d, String message) {
|
public static void checkFinite(float d, String message) {
|
||||||
if (Float.isNaN(d) || Float.isInfinite(d)) {
|
if (!isFinite(d)) {
|
||||||
throw new IllegalArgumentException(message);
|
throw new IllegalArgumentException(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue