Package freemarker.template.utility
Class NumberUtil
- java.lang.Object
-
- freemarker.template.utility.NumberUtil
-
public class NumberUtil extends java.lang.ObjectNumber- and math-related utilities.- Since:
- 2.3.20
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intgetSignum(java.lang.Number num)static booleanhasTypeThatIsKnownToNotSupportInfiniteAndNaN(java.lang.Number num)Tells if the type of the parameter number is known to not be able to represent infinite (positive or negative) and NaN.static booleanisInfinite(java.lang.Number num)static booleanisIntegerBigDecimal(java.math.BigDecimal bd)Tells if aBigDecimalstores a whole number.static booleanisNaN(java.lang.Number num)static inttoIntExact(java.lang.Number num)Converts aNumbertointwhose mathematical value is exactly the same as of the original number.
-
-
-
Method Detail
-
isInfinite
public static boolean isInfinite(java.lang.Number num)
-
isNaN
public static boolean isNaN(java.lang.Number num)
-
getSignum
public static int getSignum(java.lang.Number num) throws java.lang.ArithmeticException- Returns:
- -1 for negative, 0 for zero, 1 for positive.
- Throws:
java.lang.ArithmeticException- if the number is NaN
-
isIntegerBigDecimal
public static boolean isIntegerBigDecimal(java.math.BigDecimal bd)
Tells if aBigDecimalstores a whole number. For example, it returnstruefor1.0000, butfalsefor1.0001.- Since:
- 2.3.21
-
hasTypeThatIsKnownToNotSupportInfiniteAndNaN
public static boolean hasTypeThatIsKnownToNotSupportInfiniteAndNaN(java.lang.Number num)
Tells if the type of the parameter number is known to not be able to represent infinite (positive or negative) and NaN. If this returnsfalse, that doesn't mean that it can do that, because it's maybe just that this utility doesn't know that type.- Since:
- 2.3.28
-
toIntExact
public static int toIntExact(java.lang.Number num)
Converts aNumbertointwhose mathematical value is exactly the same as of the original number.- Throws:
java.lang.ArithmeticException- if the conversion tointis not possible without losing precision or overflow/underflow.- Since:
- 2.3.22
-
-