Class Arithmetic


  • public class Arithmetic
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int BIGDECIMAL_CODE
      Promotion code for java.math.BigDecimal.
      static int BIGINTEGER_CODE
      Promotion code for java.math.BigInteger.
      static int DOUBLE_CODE
      Promotion code double/Double.
      static int FLOAT_CODE
      Promotion code float/Float.
      static int FLONUM_CODE
      Promotion code for gnu.math.FloNum.
      static int INT_CODE
      Promotion code for byte/Byte, short/Short, int/Integer.
      static int INTNUM_CODE
      Promotion code for gnu.math.IntNum.
      static int LONG_CODE
      Promotion code for long/Long.
      static int NUMERIC_CODE
      Promotion code for other gnu.math.Numeric.
      static int RATNUM_CODE
      Promotion code for gnu.math.RatNum.
      static int REALNUM_CODE
      Promotion code for gnu.math.RealNum.
      static int UINT_CODE  
      static int ULONG_CODE  
      static int UNKNOWN_CODE  
    • Constructor Summary

      Constructors 
      Constructor Description
      Arithmetic()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.math.BigDecimal asBigDecimal​(java.lang.Object value)  
      static java.math.BigInteger asBigInteger​(java.lang.Object value)  
      static double asDouble​(java.lang.Object value)  
      static float asFloat​(java.lang.Object value)  
      static int asInt​(java.lang.Object value)  
      static IntNum asIntNum​(java.lang.Object value)  
      static IntNum asIntNum​(java.math.BigDecimal value)  
      static IntNum asIntNum​(java.math.BigInteger value)  
      static long asLong​(java.lang.Object value)  
      static Numeric asNumeric​(java.lang.Object value)  
      static RatNum asRatNum​(java.lang.Object value)  
      static int classifyType​(Type type)  
      static int classifyValue​(java.lang.Object value)  
      static java.lang.Object convert​(java.lang.Object value, int code)
      Coerce a number to one of the Arithmetic.XXX_CODE types.
      static boolean isExact​(java.lang.Number num)  
      static Type kindType​(int kind)  
      static int leastSpecificCode​(int code1, int code2)  
      static java.lang.Number toExact​(java.lang.Number num)  
      static java.lang.Number toInexact​(java.lang.Number num)  
      static java.lang.String toString​(java.lang.Object number, int radix)
      Convert a number to a String.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INT_CODE

        public static final int INT_CODE
        Promotion code for byte/Byte, short/Short, int/Integer.
        See Also:
        Constant Field Values
      • LONG_CODE

        public static final int LONG_CODE
        Promotion code for long/Long.
        See Also:
        Constant Field Values
      • BIGINTEGER_CODE

        public static final int BIGINTEGER_CODE
        Promotion code for java.math.BigInteger.
        See Also:
        Constant Field Values
      • INTNUM_CODE

        public static final int INTNUM_CODE
        Promotion code for gnu.math.IntNum.
        See Also:
        Constant Field Values
      • BIGDECIMAL_CODE

        public static final int BIGDECIMAL_CODE
        Promotion code for java.math.BigDecimal.
        See Also:
        Constant Field Values
      • RATNUM_CODE

        public static final int RATNUM_CODE
        Promotion code for gnu.math.RatNum.
        See Also:
        Constant Field Values
      • FLOAT_CODE

        public static final int FLOAT_CODE
        Promotion code float/Float.
        See Also:
        Constant Field Values
      • DOUBLE_CODE

        public static final int DOUBLE_CODE
        Promotion code double/Double.
        See Also:
        Constant Field Values
      • FLONUM_CODE

        public static final int FLONUM_CODE
        Promotion code for gnu.math.FloNum.
        See Also:
        Constant Field Values
      • REALNUM_CODE

        public static final int REALNUM_CODE
        Promotion code for gnu.math.RealNum.
        See Also:
        Constant Field Values
      • NUMERIC_CODE

        public static final int NUMERIC_CODE
        Promotion code for other gnu.math.Numeric.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Arithmetic

        public Arithmetic()
    • Method Detail

      • leastSpecificCode

        public static int leastSpecificCode​(int code1,
                                            int code2)
      • classifyValue

        public static int classifyValue​(java.lang.Object value)
      • kindType

        public static Type kindType​(int kind)
      • classifyType

        public static int classifyType​(Type type)
      • asInt

        public static int asInt​(java.lang.Object value)
      • asLong

        public static long asLong​(java.lang.Object value)
      • asFloat

        public static float asFloat​(java.lang.Object value)
      • asDouble

        public static double asDouble​(java.lang.Object value)
      • asBigInteger

        public static java.math.BigInteger asBigInteger​(java.lang.Object value)
      • asIntNum

        public static IntNum asIntNum​(java.math.BigDecimal value)
      • asIntNum

        public static IntNum asIntNum​(java.math.BigInteger value)
      • asIntNum

        public static IntNum asIntNum​(java.lang.Object value)
      • asBigDecimal

        public static java.math.BigDecimal asBigDecimal​(java.lang.Object value)
      • asRatNum

        public static RatNum asRatNum​(java.lang.Object value)
      • asNumeric

        public static Numeric asNumeric​(java.lang.Object value)
      • toString

        public static java.lang.String toString​(java.lang.Object number,
                                                int radix)
        Convert a number to a String. Handles classes subclasses of gnu.math.Numeric as well as standard Java classes.
      • convert

        public static java.lang.Object convert​(java.lang.Object value,
                                               int code)
        Coerce a number to one of the Arithmetic.XXX_CODE types. Assumes > Arithmetic.classifyValue(value), though the converse might also work.
      • isExact

        public static boolean isExact​(java.lang.Number num)
      • toExact

        public static java.lang.Number toExact​(java.lang.Number num)
      • toInexact

        public static java.lang.Number toInexact​(java.lang.Number num)