org.eigenbase.util14
Class NumberUtil

java.lang.Object
  extended by org.eigenbase.util14.NumberUtil

public class NumberUtil
extends Object

Utility functions for working with numbers This class is JDK 1.4 compatible.

Since:
Jan 9, 2006
Version:
$Id: //open/dev/farrago/src/org/eigenbase/util14/NumberUtil.java#12 $
Author:
angel

Field Summary
private static BigInteger[] bigIntMaxUnscaled
           
private static BigInteger[] bigIntMinUnscaled
           
private static BigInteger bigIntTen
           
private static BigInteger[] bigIntTenPow
           
private static DecimalFormat doubleFormatter
           
private static DecimalFormat floatFormatter
           
static Integer INTEGER_ONE
           
static Integer INTEGER_ZERO
           
static Byte MAX_BYTE
           
static Double MAX_DOUBLE
           
static Float MAX_FLOAT
           
static Integer MAX_INTEGER
           
static Long MAX_LONG
           
static Short MAX_SHORT
           
static Byte MIN_BYTE
           
static Double MIN_DOUBLE
           
static Float MIN_FLOAT
           
static Integer MIN_INTEGER
           
static Long MIN_LONG
           
static Short MIN_SHORT
           
 
Constructor Summary
NumberUtil()
           
 
Method Summary
static Double add(Double a, Double b)
           
static Double divide(Double a, Double b)
           
static NumberFormat getApproxFormatter(boolean isFloat)
           
static BigInteger getMaxUnscaled(int precision)
           
static BigInteger getMinUnscaled(int precision)
           
static boolean isValidDecimal(BigDecimal bd)
           
static Double multiply(Double a, Double b)
           
static BigInteger powTen(int exponent)
           
static BigDecimal rescaleBigDecimal(BigDecimal bd, int scale)
           
static long round(double d)
           
static BigDecimal toBigDecimal(Number number)
           
static BigDecimal toBigDecimal(Number number, int scale)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

floatFormatter

private static final DecimalFormat floatFormatter

doubleFormatter

private static final DecimalFormat doubleFormatter

bigIntTenPow

private static final BigInteger[] bigIntTenPow

bigIntMinUnscaled

private static final BigInteger[] bigIntMinUnscaled

bigIntMaxUnscaled

private static final BigInteger[] bigIntMaxUnscaled

bigIntTen

private static final BigInteger bigIntTen

MIN_BYTE

public static final Byte MIN_BYTE

MAX_BYTE

public static final Byte MAX_BYTE

MIN_INTEGER

public static final Integer MIN_INTEGER

MAX_INTEGER

public static final Integer MAX_INTEGER

MIN_SHORT

public static final Short MIN_SHORT

MAX_SHORT

public static final Short MAX_SHORT

MIN_LONG

public static final Long MIN_LONG

MAX_LONG

public static final Long MAX_LONG

MIN_FLOAT

public static final Float MIN_FLOAT

MAX_FLOAT

public static final Float MAX_FLOAT

MIN_DOUBLE

public static final Double MIN_DOUBLE

MAX_DOUBLE

public static final Double MAX_DOUBLE

INTEGER_ZERO

public static final Integer INTEGER_ZERO

INTEGER_ONE

public static final Integer INTEGER_ONE
Constructor Detail

NumberUtil

public NumberUtil()
Method Detail

powTen

public static final BigInteger powTen(int exponent)

getMaxUnscaled

public static final BigInteger getMaxUnscaled(int precision)

getMinUnscaled

public static final BigInteger getMinUnscaled(int precision)

rescaleBigDecimal

public static final BigDecimal rescaleBigDecimal(BigDecimal bd,
                                                 int scale)

toBigDecimal

public static final BigDecimal toBigDecimal(Number number,
                                            int scale)

toBigDecimal

public static final BigDecimal toBigDecimal(Number number)

isValidDecimal

public static boolean isValidDecimal(BigDecimal bd)
Returns:
whether a BigDecimal is a valid Farrago decimal. If a BigDecimal's unscaled value overflows a long, then it is not a valid Farrago decimal.

getApproxFormatter

public static NumberFormat getApproxFormatter(boolean isFloat)

round

public static long round(double d)

add

public static Double add(Double a,
                         Double b)

divide

public static Double divide(Double a,
                            Double b)

multiply

public static Double multiply(Double a,
                              Double b)