mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-15 05:33:40 +00:00
37 lines
952 B
Java
37 lines
952 B
Java
![]() |
package com.earth2me.essentials.utils;
|
||
|
|
||
|
/**
|
||
|
* parseFloat and parseDouble proxies that are protected against non-finite values.
|
||
|
*/
|
||
|
public class FloatUtil
|
||
|
{
|
||
|
private FloatUtil() {}
|
||
|
|
||
|
public static float parseFloat(String s) throws NumberFormatException
|
||
|
{
|
||
|
float f = Float.parseFloat(s);
|
||
|
if (Float.isNaN(f))
|
||
|
{
|
||
|
throw new NumberFormatException("NaN is not valid");
|
||
|
}
|
||
|
if (Float.isInfinite(f))
|
||
|
{
|
||
|
throw new NumberFormatException("Infinity is not valid");
|
||
|
}
|
||
|
return f;
|
||
|
}
|
||
|
|
||
|
public static double parseDouble(String s) throws NumberFormatException
|
||
|
{
|
||
|
double d = Double.parseDouble(s);
|
||
|
if (Double.isNaN(d))
|
||
|
{
|
||
|
throw new NumberFormatException("NaN is not valid");
|
||
|
}
|
||
|
if (Double.isInfinite(d))
|
||
|
{
|
||
|
throw new NumberFormatException("Infinity is not valid");
|
||
|
}
|
||
|
return d;
|
||
|
}
|
||
|
}
|