gnu.kawa.functions

Class Arithmetic


public class Arithmetic
extends java.lang.Object

Various utility methods and conversions for handling mixed-mode arithmetic. This should possibly be moved to gnu.math.

Field Summary

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
INTNUM_CODE
Promotion code for gnu.math.IntNum.
static int
INT_CODE
Promotion code for byte/Byte, short/Short, int/Integer.
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 IntNum
ten_exp_9

Method Summary

static BigDecimal
asBigDecimal(Object value)
static BigInteger
asBigInteger(Object value)
static double
asDouble(Object value)
static float
asFloat(Object value)
static int
asInt(Object value)
static IntNum
asIntNum(BigDecimal value)
static IntNum
asIntNum(BigInteger value)
static IntNum
asIntNum(Object value)
static long
asLong(Object value)
static Numeric
asNumeric(Object value)
static RatNum
asRatNum(Object value)
static int
classifyValue(Object value)
static Object
convert(Object value, int code)
Coerce a number to one of the Arithmetic.XXX_CODE types.
static String
toString(Object number, int radix)
Convert a number to a String.

Field Details

BIGDECIMAL_CODE

public static final int BIGDECIMAL_CODE
Promotion code for java.math.BigDecimal.
Field Value:
5

BIGINTEGER_CODE

public static final int BIGINTEGER_CODE
Promotion code for java.math.BigInteger.
Field Value:
3

DOUBLE_CODE

public static final int DOUBLE_CODE
Promotion code double/Double.
Field Value:
8

FLOAT_CODE

public static final int FLOAT_CODE
Promotion code float/Float.
Field Value:
7

FLONUM_CODE

public static final int FLONUM_CODE
Promotion code for gnu.math.FloNum.
Field Value:
9

INTNUM_CODE

public static final int INTNUM_CODE
Promotion code for gnu.math.IntNum.
Field Value:
4

INT_CODE

public static final int INT_CODE
Promotion code for byte/Byte, short/Short, int/Integer.
Field Value:
1

LONG_CODE

public static final int LONG_CODE
Promotion code for long/Long.
Field Value:
2

NUMERIC_CODE

public static final int NUMERIC_CODE
Promotion code for other gnu.math.Numeric.
Field Value:
10

RATNUM_CODE

public static final int RATNUM_CODE
Promotion code for gnu.math.RatNum.
Field Value:
6

ten_exp_9

public static final IntNum ten_exp_9

Method Details

asBigDecimal

public static BigDecimal asBigDecimal(Object value)

asBigInteger

public static BigInteger asBigInteger(Object value)

asDouble

public static double asDouble(Object value)

asFloat

public static float asFloat(Object value)

asInt

public static int asInt(Object value)

asIntNum

public static IntNum asIntNum(BigDecimal value)

asIntNum

public static IntNum asIntNum(BigInteger value)

asIntNum

public static IntNum asIntNum(Object value)

asLong

public static long asLong(Object value)

asNumeric

public static Numeric asNumeric(Object value)

asRatNum

public static RatNum asRatNum(Object value)

classifyValue

public static int classifyValue(Object value)

convert

public static Object convert(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.

toString

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