public class NumberUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.math.BigInteger |
MINUS_ONE |
Constructor and Description |
---|
NumberUtil() |
Modifier and Type | Method and Description |
---|---|
static java.math.BigInteger |
ceiling(org.apache.commons.math4.fraction.BigFraction f)
Ceiling, round towards positive infinity.
|
static java.math.BigInteger |
checkNonNegative(java.lang.String role,
java.math.BigInteger x) |
static double |
checkNonNegative(java.lang.String role,
double x) |
static int |
checkNonNegative(java.lang.String role,
int x) |
static long |
checkNonNegative(java.lang.String role,
long x) |
static java.math.BigInteger |
checkPositive(java.lang.String role,
java.math.BigInteger x) |
static int |
checkPositive(java.lang.String role,
int x) |
static long |
checkPositive(java.lang.String role,
long x) |
static java.math.BigInteger[] |
convertToFraction(double value)
Convert a
double number into a reduced ratio of two
BigIntegers that mathematically represents exactly the same value. |
static java.math.BigInteger |
floor(org.apache.commons.math4.fraction.BigFraction f)
Floor, round towards negative infinity.
|
static org.apache.commons.math4.fraction.BigFraction |
fractionalPart(org.apache.commons.math4.fraction.BigFraction f)
Fractional part.
|
static java.math.BigInteger |
integerPart(org.apache.commons.math4.fraction.BigFraction f)
Integer part.
|
static org.apache.commons.math4.fraction.BigFraction |
inverse(org.apache.commons.math4.fraction.BigFraction fraction) |
static boolean |
isEven(java.math.BigInteger a) |
static boolean |
isInt(java.math.BigInteger a,
int value)
Test if this BigInteger equals the given
int value. |
static boolean |
isLargerThan(org.apache.commons.math4.fraction.BigFraction a,
org.apache.commons.math4.fraction.BigFraction b)
Compares the absolute value of two rational numbers.
|
static boolean |
isMinusOne(java.math.BigInteger a) |
static boolean |
isNegative(org.apache.commons.math4.fraction.BigFraction a) |
static boolean |
isNegative(java.math.BigInteger a) |
static boolean |
isOdd(java.math.BigInteger a) |
static boolean |
isOne(java.math.BigInteger a) |
static boolean |
isPerfectSquare(org.apache.commons.math4.fraction.BigFraction bf)
Test if the fraction value is a perfect square (i.e. its numerator's and
denominator's square root are integers).
|
static boolean |
isPerfectSquare(java.math.BigInteger bi)
Test if the value is a perfect square (i.e. its square root is another
integer).
|
static boolean |
isPerfectSquare(IRational bf)
Test if the fraction value is a perfect square (i.e. its numerator's and
denominator's square root are integers).
|
static boolean |
isPerfectSquare(long n)
Test if a long value is a perfect square (i.e. its square root is another
integer).
|
static boolean |
isPositive(org.apache.commons.math4.fraction.BigFraction a) |
static boolean |
isPositive(java.math.BigInteger a) |
static boolean |
isZero(org.apache.commons.math4.fraction.BigFraction fraction) |
static boolean |
isZero(java.math.BigInteger a) |
static boolean |
isZero(IExpr e) |
static java.math.BigInteger |
round(org.apache.commons.math4.fraction.BigFraction f,
int roundMode)
Round.
|
static int |
toInt(java.math.BigInteger a)
Converts this number to
int ; unlike #intValue this
method raises ArithmeticException if this integer cannot be
represented by an int type. |
static int |
toInt(double d)
Converts this number to
int ; unlike #intValue this
method raises ArithmeticException if this integer cannot be
represented by an int type. |
static long |
toLong(java.math.BigInteger a) |
static long |
toLong(double d)
Converts this number to
long ; unlike #longValue this
method raises ArithmeticException if this integer cannot be
represented by an long type. |
static java.math.BigInteger |
trunc(org.apache.commons.math4.fraction.BigFraction f)
Truncate, round towards zero.
|
public static boolean isZero(IExpr e)
public static boolean isZero(org.apache.commons.math4.fraction.BigFraction fraction)
public static org.apache.commons.math4.fraction.BigFraction inverse(org.apache.commons.math4.fraction.BigFraction fraction)
public static boolean isNegative(java.math.BigInteger a)
public static boolean isPositive(java.math.BigInteger a)
public static boolean isZero(java.math.BigInteger a)
public static boolean isOne(java.math.BigInteger a)
public static boolean isMinusOne(java.math.BigInteger a)
public static boolean isEven(java.math.BigInteger a)
public static boolean isOdd(java.math.BigInteger a)
public static long toLong(java.math.BigInteger a) throws java.lang.ArithmeticException
java.lang.ArithmeticException
public static int toInt(java.math.BigInteger a) throws java.lang.ArithmeticException
int
; unlike #intValue
this
method raises ArithmeticException
if this integer cannot be
represented by an int
type.int
.java.lang.ArithmeticException
- if conversion to int
is not possible.public static boolean isInt(java.math.BigInteger a, int value) throws java.lang.ArithmeticException
int
value.java.lang.ArithmeticException
public static int toInt(double d) throws java.lang.ArithmeticException
int
; unlike #intValue
this
method raises ArithmeticException
if this integer cannot be
represented by an int
type.int
.java.lang.ArithmeticException
- if conversion to int
is not possible.public static long toLong(double d) throws java.lang.ArithmeticException
long
; unlike #longValue
this
method raises ArithmeticException
if this integer cannot be
represented by an long
type.long
.java.lang.ArithmeticException
- if conversion to long
is not possible.public static boolean isLargerThan(org.apache.commons.math4.fraction.BigFraction a, org.apache.commons.math4.fraction.BigFraction b)
that
- the rational number to be compared with.|this| > |that|
public static boolean isNegative(org.apache.commons.math4.fraction.BigFraction a)
public static boolean isPositive(org.apache.commons.math4.fraction.BigFraction a)
public static java.math.BigInteger floor(org.apache.commons.math4.fraction.BigFraction f)
Possible loss of precision.
public static java.math.BigInteger ceiling(org.apache.commons.math4.fraction.BigFraction f)
Possible loss of precision.
public static java.math.BigInteger trunc(org.apache.commons.math4.fraction.BigFraction f)
Possible loss of precision.
public static java.math.BigInteger integerPart(org.apache.commons.math4.fraction.BigFraction f)
Possible loss of precision.
public static org.apache.commons.math4.fraction.BigFraction fractionalPart(org.apache.commons.math4.fraction.BigFraction f)
Possible loss of precision.
public static java.math.BigInteger round(org.apache.commons.math4.fraction.BigFraction f, int roundMode)
Round mode is one of {
ROUND_UP, ROUND_DOWN, ROUND_CEILING, ROUND_FLOOR,
ROUND_HALF_UP, ROUND_HALF_DOWN, ROUND_HALF_EVEN,
ROUND_HALF_CEILING, ROUND_HALF_FLOOR, ROUND_HALF_ODD,
ROUND_UNNECESSARY, DEFAULT_ROUND_MODE (==ROUND_HALF_UP)
.
If rounding isn't necessary, i.e. this BigRational is an integer, [as an optimization] this BigRational is returned.
Possible loss of precision.
public static final boolean isPerfectSquare(java.math.BigInteger bi)
bi
- true
if the number is a perfect square.public static final boolean isPerfectSquare(org.apache.commons.math4.fraction.BigFraction bf)
bf
- true
if the number is a perfect square.public static final boolean isPerfectSquare(IRational bf)
bf
- true
if the number is a perfect square.public static final boolean isPerfectSquare(long n)
n
- true
if the number is a perfect square.public static java.math.BigInteger[] convertToFraction(double value)
double
number into a reduced ratio of two
BigIntegers that mathematically represents exactly the same value.
See: http://
stackoverflow.com/questions/27259162value
- public static int checkPositive(java.lang.String role, int x)
public static long checkPositive(java.lang.String role, long x)
public static java.math.BigInteger checkPositive(java.lang.String role, java.math.BigInteger x)
public static int checkNonNegative(java.lang.String role, int x)
public static long checkNonNegative(java.lang.String role, long x)
public static java.math.BigInteger checkNonNegative(java.lang.String role, java.math.BigInteger x)
public static double checkNonNegative(java.lang.String role, double x)