org.matheclipse.core.expression
Class NumberUtil
- java.lang.Object
-
- org.matheclipse.core.expression.NumberUtil
-
public class NumberUtil extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field and Description static java.math.BigIntegerMINUS_ONE
-
Constructor Summary
Constructors Constructor and Description NumberUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static java.math.BigIntegerceiling(BigFraction f)Ceiling, round towards positive infinity.static java.math.BigIntegerfloor(BigFraction f)Floor, round towards negative infinity.static BigFractionfractionalPart(BigFraction f)Fractional part.static java.math.BigIntegerintegerPart(BigFraction f)Integer part.static BigFractioninverse(BigFraction fraction)static booleanisEven(java.math.BigInteger a)static booleanisLargerThan(BigFraction a, BigFraction b)Compares the absolute value of two rational numbers.static booleanisLargerThan(java.math.BigInteger a, java.math.BigInteger b)static booleanisLessThan(java.math.BigInteger a, java.math.BigInteger b)static booleanisMinusOne(java.math.BigInteger a)static booleanisMinusOne(IExpr i)static booleanisNegative(BigFraction a)static booleanisNegative(java.math.BigInteger a)static booleanisOdd(java.math.BigInteger a)static booleanisOne(java.math.BigInteger a)static booleanisOne(IExpr i)static booleanisPerfectSquare(BigFraction bf)Test if the fraction value is a perfect square (i.e.static booleanisPerfectSquare(java.math.BigInteger bi)Test if the value is a perfect square (i.e.static booleanisPerfectSquare(long n)Test if a long value is a perfect square (i.e.static booleanisPositive(BigFraction a)static booleanisPositive(java.math.BigInteger a)static booleanisZero(BigFraction fraction)static booleanisZero(java.math.BigInteger a)static booleanisZero(IExpr e)static java.math.BigIntegerround(BigFraction f, int roundMode)Round.static inttoInt(java.math.BigInteger a)Converts this number toint; unlike#intValuethis method raisesArithmeticExceptionif this integer cannot be represented by aninttype.static inttoInt(double d)Converts this number toint; unlike#intValuethis method raisesArithmeticExceptionif this integer cannot be represented by aninttype.static longtoLong(java.math.BigInteger a)static longtoLong(double d)Converts this number tolong; unlike#longValuethis method raisesArithmeticExceptionif this integer cannot be represented by anlongtype.static java.math.BigIntegertrunc(BigFraction f)Truncate, round towards zero.
-
-
-
Method Detail
-
isZero
public static boolean isZero(IExpr e)
-
isZero
public static boolean isZero(BigFraction fraction)
-
inverse
public static BigFraction inverse(BigFraction fraction)
-
isOne
public static boolean isOne(IExpr i)
-
isMinusOne
public static boolean isMinusOne(IExpr i)
-
isLargerThan
public static boolean isLargerThan(java.math.BigInteger a, java.math.BigInteger b)
-
isLessThan
public static boolean isLessThan(java.math.BigInteger a, java.math.BigInteger b)
-
isNegative
public static boolean isNegative(java.math.BigInteger a)
-
isPositive
public static boolean isPositive(java.math.BigInteger a)
-
isZero
public static boolean isZero(java.math.BigInteger a)
-
isOne
public static boolean isOne(java.math.BigInteger a)
-
isMinusOne
public static boolean isMinusOne(java.math.BigInteger a)
-
isEven
public static boolean isEven(java.math.BigInteger a)
-
isOdd
public static boolean isOdd(java.math.BigInteger a)
-
toLong
public static long toLong(java.math.BigInteger a) throws java.lang.ArithmeticException- Throws:
java.lang.ArithmeticException
-
toInt
public static int toInt(java.math.BigInteger a) throws java.lang.ArithmeticExceptionConverts this number toint; unlike#intValuethis method raisesArithmeticExceptionif this integer cannot be represented by aninttype.- Returns:
- the numeric value represented by this integer after conversion to type
int. - Throws:
java.lang.ArithmeticException- if conversion tointis not possible.
-
toInt
public static int toInt(double d) throws java.lang.ArithmeticExceptionConverts this number toint; unlike#intValuethis method raisesArithmeticExceptionif this integer cannot be represented by aninttype.- Returns:
- the numeric value represented by this number after conversion to type
int. - Throws:
java.lang.ArithmeticException- if conversion tointis not possible.
-
toLong
public static long toLong(double d) throws java.lang.ArithmeticExceptionConverts this number tolong; unlike#longValuethis method raisesArithmeticExceptionif this integer cannot be represented by anlongtype.- Returns:
- the numeric value represented by this number after conversion to type
long. - Throws:
java.lang.ArithmeticException- if conversion tolongis not possible.
-
isLargerThan
public static boolean isLargerThan(BigFraction a, BigFraction b)
Compares the absolute value of two rational numbers.- Parameters:
that- the rational number to be compared with.- Returns:
|this| > |that|
-
isNegative
public static boolean isNegative(BigFraction a)
-
isPositive
public static boolean isPositive(BigFraction a)
-
floor
public static java.math.BigInteger floor(BigFraction f)
Floor, round towards negative infinity.Possible loss of precision.
-
ceiling
public static java.math.BigInteger ceiling(BigFraction f)
Ceiling, round towards positive infinity.Possible loss of precision.
-
trunc
public static java.math.BigInteger trunc(BigFraction f)
Truncate, round towards zero.Possible loss of precision.
-
integerPart
public static java.math.BigInteger integerPart(BigFraction f)
Integer part.Possible loss of precision.
-
fractionalPart
public static BigFraction fractionalPart(BigFraction f)
Fractional part.Possible loss of precision.
-
round
public static java.math.BigInteger round(BigFraction f, int roundMode)
Round.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.
-
isPerfectSquare
public static final boolean isPerfectSquare(java.math.BigInteger bi)
Test if the value is a perfect square (i.e. its square root is another integer). See Stackoverflow.com - Fastest way to determine if an integer's square root is an integer- Parameters:
bi-- Returns:
trueif the number is a perfect square.
-
isPerfectSquare
public static final boolean isPerfectSquare(BigFraction bf)
Test if the fraction value is a perfect square (i.e. its numerator's and denominator's square root are integers). See Stackoverflow.com - Fastest way to determine if an integer's square root is an integer- Parameters:
bf-- Returns:
trueif the number is a perfect square.
-
isPerfectSquare
public static final boolean isPerfectSquare(long n)
Test if a long value is a perfect square (i.e. its square root is another integer). See Stackoverflow.com - Fastest way to determine if an integer's square root is an integer- Parameters:
n-- Returns:
trueif the number is a perfect square.
-
-
DMelt 3.0 © DataMelt by jWork.ORG