Class NumberCentral
java.lang.Object
org.znerd.math.NumberCentral
A static factory that produces
RealNumber objects.- Version:
- $Revision: 1.17 $ $Date: 2002/10/01 18:47:57 $
- Author:
- Ernst de Haan (znerd@FreeBSD.org)
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidChecks if dividing by the specified number would result in a division by zero.static RationalNumbercreateFraction(int numerator, int denominator) Returns a fraction with the given numerator and denominator, both being anint.static RationalNumbercreateFraction(IntegerNumber numerator, IntegerNumber denominator) Returns a fraction with the given numerator and denominator.static IntegerNumbercreateInteger(byte[] bytes) Returns an integer number from a byte array in two's complement notation.static IntegerNumbercreateRandomInteger(int numBytes) Returns anIntegerNumberwith a random value.static StringReturns the current version of JUMP.static IntegerNumbervalueOf(byte n) Converts abyteto anIntegerNumber.static RationalNumbervalueOf(double n) Converts adoubleto aRationalNumber.static RationalNumbervalueOf(float n) Converts afloatto aRationalNumber.static IntegerNumbervalueOf(int n) Converts anintto anIntegerNumber.static IntegerNumbervalueOf(long n) Converts alongto anIntegerNumber.static IntegerNumbervalueOf(short n) Converts ashortto anIntegerNumber.static RationalNumberConverts aBigDecimalto aRationalNumber.static IntegerNumberConverts aBigIntegerto anIntegerNumber.
-
Method Details
-
getVersion
Returns the current version of JUMP.- Returns:
- the version of JUMP, for example
"0.5", nevernull.
-
createFraction
public static RationalNumber createFraction(int numerator, int denominator) throws ArithmeticException Returns a fraction with the given numerator and denominator, both being anint.- Parameters:
numerator- the numerator for the fraction.denominator- the denominator for the fraction, not 0.- Returns:
- the rational number, never
null. - Throws:
ArithmeticException- ifdenominator == 0.
-
createFraction
public static RationalNumber createFraction(IntegerNumber numerator, IntegerNumber denominator) throws ArithmeticException, IllegalArgumentException Returns a fraction with the given numerator and denominator.- Parameters:
numerator- the numerator for the fraction, notnull.denominator- the denominator for the fraction, notnull.- Returns:
- the fraction, never
null. - Throws:
IllegalArgumentException- ifnumerator == null || denominator == null.ArithmeticException- if the denominator is zero, i.e.denominator.equals(.SmallIntegerNumber.ZERO)
-
createInteger
Returns an integer number from a byte array in two's complement notation.- Parameters:
bytes- the two's complement byte array, notnull.- Returns:
- an integer number that has the same value as represented by the
argument, never
null. - Throws:
IllegalArgumentException- ifbytes == null.
-
valueOf
Converts adoubleto aRationalNumber.- Parameters:
n- the value to be converted, not an infinite number, nor NaN.- Returns:
- the result of the conversion, never
null. - Throws:
IllegalArgumentException- ifDouble.isInfinite(n) || Double.isNaN(n)
-
valueOf
Converts afloatto aRationalNumber.- Parameters:
n- the value to be converted.- Returns:
- the result of the conversion, never
null. - Throws:
IllegalArgumentException- ifFloat.isInfinite(n) || Float.isNaN(n)
-
valueOf
Converts alongto anIntegerNumber.- Parameters:
n- the value to be converted.- Returns:
- the result of the conversion, never
null.
-
valueOf
Converts anintto anIntegerNumber.- Parameters:
n- the value to be converted.- Returns:
- the result of the conversion, never
null.
-
valueOf
Converts ashortto anIntegerNumber.- Parameters:
n- the value to be converted.- Returns:
- the result of the conversion, never
null.
-
valueOf
Converts abyteto anIntegerNumber.- Parameters:
n- the value to be converted.- Returns:
- the result of the conversion, never
null.
-
valueOf
Converts aBigIntegerto anIntegerNumber.- Parameters:
n- the value to be converted, notnull.- Returns:
- the result of the conversion, never
null. - Throws:
IllegalArgumentException- ifn == null.
-
valueOf
Converts aBigDecimalto aRationalNumber.- Parameters:
n- the value to be converted, notnull.- Returns:
- the result of the conversion, never
null. - Throws:
IllegalArgumentException- ifn == null.
-
createRandomInteger
Returns anIntegerNumberwith a random value. The maximum number of bytes for the integer number must be specified.- Parameters:
numBytes- the maximum number of bytes for the constructed number, at least 1.- Returns:
- a random integer, never
null. - Throws:
IllegalArgumentException- ifnumBytes < 1.
-
checkDivideByZero
public static void checkDivideByZero(RealNumber n) throws IllegalArgumentException, ArithmeticException Checks if dividing by the specified number would result in a division by zero. If the argument indeed represents zero, then anArithmeticExceptionis thrown.- Parameters:
n- the number to compare with zero, notnull.- Throws:
IllegalArgumentException- ifn == null.ArithmeticException- ifn..getSign() == 0
-