Math


The class Range and subclasses DoubleRange, FloatRange, IntRange, LongRange, and NumberRange are used to store inclusive ranges of numbers. These range classes can be interrogated for containment, minimums, and maximums.

The Fraction class allows you to work with fractions accurately. Fractions are stored as you might write them. For example, the code:

 Fraction myFraction = Fraction.getFraction(2, 3, 5); System.out.println(myFraction.floatValue()); Fraction secondFraction = Fraction.getFraction(1, 1, 3); System.out.println(secondFraction.floatValue()); myFraction = myFraction.add(secondFraction); System.out.println(myFraction.floatValue()); System.out.print(myFraction.getProperWhole() + " "); System.out.print(myFraction.getProperNumerator() + "/"); System.out.println(myFraction.getDenominator()); 

. . . outputs the values:

 2.6 1.3333334 3.9333334 3 14/15 

Note that the float values are represented by a rounded-off value, whereas the Fraction is stored precisely. The Fraction class allows you to parse a string in the standard format X Y/Z (such as 3 14/15) into a Fraction.

The JVMRandom and RandomUtils classes provide wrappers to return various primitive values from the Math.random method. RandomUtils caches the Random object, with each method returning a new value from the same system-wide seed, whereas multiple JVMRandom objects can be created if multiple random number seeds are desired.

The NumberUtils class provides static constants for various 0 and 1 values, utility checks to verify that a String is actually a number, max and min checks for a wide variety of types including arrays, and methods to automatically convert strings directly to int values.



    Apache Jakarta Commons(c) Reusable Java Components
    Real World Web Services
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 137
    Authors: Will Iverson

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net