Class NumberCentral

java.lang.Object
org.znerd.math.NumberCentral

public final class NumberCentral extends Object
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 Details

    • getVersion

      public static String getVersion()
      Returns the current version of JUMP.
      Returns:
      the version of JUMP, for example "0.5", never null.
    • createFraction

      public static RationalNumber createFraction(int numerator, int denominator) throws ArithmeticException
      Returns a fraction with the given numerator and denominator, both being an int.
      Parameters:
      numerator - the numerator for the fraction.
      denominator - the denominator for the fraction, not 0.
      Returns:
      the rational number, never null.
      Throws:
      ArithmeticException - if denominator == 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, not null.
      denominator - the denominator for the fraction, not null.
      Returns:
      the fraction, never null.
      Throws:
      IllegalArgumentException - if numerator == null || denominator == null.
      ArithmeticException - if the denominator is zero, i.e. denominator.equals(SmallIntegerNumber.ZERO).
    • createInteger

      public static IntegerNumber createInteger(byte[] bytes) throws IllegalArgumentException
      Returns an integer number from a byte array in two's complement notation.
      Parameters:
      bytes - the two's complement byte array, not null.
      Returns:
      an integer number that has the same value as represented by the argument, never null.
      Throws:
      IllegalArgumentException - if bytes == null.
    • valueOf

      public static RationalNumber valueOf(double n) throws IllegalArgumentException
      Converts a double to a RationalNumber.
      Parameters:
      n - the value to be converted, not an infinite number, nor NaN.
      Returns:
      the result of the conversion, never null.
      Throws:
      IllegalArgumentException - if Double.isInfinite(n) || Double.isNaN(n)
    • valueOf

      public static RationalNumber valueOf(float n) throws IllegalArgumentException
      Converts a float to a RationalNumber.
      Parameters:
      n - the value to be converted.
      Returns:
      the result of the conversion, never null.
      Throws:
      IllegalArgumentException - if Float.isInfinite(n) || Float.isNaN(n)
    • valueOf

      public static IntegerNumber valueOf(long n)
      Converts a long to an IntegerNumber.
      Parameters:
      n - the value to be converted.
      Returns:
      the result of the conversion, never null.
    • valueOf

      public static IntegerNumber valueOf(int n)
      Converts an int to an IntegerNumber.
      Parameters:
      n - the value to be converted.
      Returns:
      the result of the conversion, never null.
    • valueOf

      public static IntegerNumber valueOf(short n)
      Converts a short to an IntegerNumber.
      Parameters:
      n - the value to be converted.
      Returns:
      the result of the conversion, never null.
    • valueOf

      public static IntegerNumber valueOf(byte n)
      Converts a byte to an IntegerNumber.
      Parameters:
      n - the value to be converted.
      Returns:
      the result of the conversion, never null.
    • valueOf

      public static IntegerNumber valueOf(BigInteger n) throws IllegalArgumentException
      Converts a BigInteger to an IntegerNumber.
      Parameters:
      n - the value to be converted, not null.
      Returns:
      the result of the conversion, never null.
      Throws:
      IllegalArgumentException - if n == null.
    • valueOf

      public static RationalNumber valueOf(BigDecimal n) throws IllegalArgumentException
      Converts a BigDecimal to a RationalNumber.
      Parameters:
      n - the value to be converted, not null.
      Returns:
      the result of the conversion, never null.
      Throws:
      IllegalArgumentException - if n == null.
    • createRandomInteger

      public static IntegerNumber createRandomInteger(int numBytes) throws IllegalArgumentException
      Returns an IntegerNumber with 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 - if numBytes < 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 an ArithmeticException is thrown.
      Parameters:
      n - the number to compare with zero, not null.
      Throws:
      IllegalArgumentException - if n == null.
      ArithmeticException - if n.getSign() == 0.