mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-24 01:06:01 +01:00
Add isFinite util methods.
By: md_5 <git@md-5.net>
This commit is contained in:
parent
55b9c40dda
commit
925591bd64
1 changed files with 10 additions and 2 deletions
|
@ -102,14 +102,22 @@ public final class NumberConversions {
|
|||
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) {
|
||||
if (Double.isNaN(d) || Double.isInfinite(d)) {
|
||||
if (!isFinite(d)) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkFinite(float d, String message) {
|
||||
if (Float.isNaN(d) || Float.isInfinite(d)) {
|
||||
if (!isFinite(d)) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue