Commits

md_5 authored 2b22e68f5a9
Add isFinite util methods.
No tags

src/main/java/org/bukkit/util/NumberConversions.java

Modified
95 95 }
96 96
97 97 try {
98 98 return Byte.valueOf(object.toString());
99 99 } catch (NumberFormatException e) {
100 100 } catch (NullPointerException e) {
101 101 }
102 102 return 0;
103 103 }
104 104
105 + public static boolean isFinite(double d) {
106 + return Math.abs(d) <= Double.MAX_VALUE;
107 + }
108 +
109 + public static boolean isFinite(float f) {
110 + return Math.abs(f) <= Float.MAX_VALUE;
111 + }
112 +
105 113 public static void checkFinite(double d, String message) {
106 - if (Double.isNaN(d) || Double.isInfinite(d)) {
114 + if (!isFinite(d)) {
107 115 throw new IllegalArgumentException(message);
108 116 }
109 117 }
110 118
111 119 public static void checkFinite(float d, String message) {
112 - if (Float.isNaN(d) || Float.isInfinite(d)) {
120 + if (!isFinite(d)) {
113 121 throw new IllegalArgumentException(message);
114 122 }
115 123 }
116 124 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut