org.geotoolkit.math
Class XMath

Object
  extended by Static
      extended by XMath

public final class XMath
extends Static

Simple mathematical functions in addition to the ones provided in Math.

Since:
1.0
Version:
3.20
Author:
Martin Desruisseaux (MPO, IRD, Geomatys)
Module:
utility/geotk-utility (download)    View source code for this class

Field Summary
static long SIGN_BIT_MASK
          Deprecated. No replacement (this is considered internal mechanic).
static double SQRT2
          Deprecated. Moved to Apache SIS MathFunctions.SQRT_2.
 
Method Summary
static double adjacentForType(Class<? extends Number> type, double value, int amount)
          Returns the number adjacent to the given value, as one of the nearest representable numbers of the given type.
static double atanh(double x)
          Deprecated. Moved to Apache SIS MathFunctions.atanh(double).
static int[] commonDivisors(int... numbers)
          Deprecated. Moved to Apache SIS MathFunctions.commonDivisors(int[]).
static int[] divisors(int number)
          Deprecated. Moved to Apache SIS MathFunctions.divisors(int).
static boolean isNegative(double value)
          Deprecated. Moved to Apache SIS MathFunctions.isNegative(double).
static boolean isPositive(double value)
          Deprecated. Moved to Apache SIS MathFunctions.isPositive(double).
static boolean isSameSign(double v1, double v2)
          Deprecated. Moved to Apache SIS MathFunctions.isSameSign(double, double).
static double magnitude(double... vector)
          Deprecated. Moved to Apache SIS MathFunctions.magnitude(double[]).
static double pow10(double x)
          Deprecated. Moved to Apache SIS MathFunctions.pow10(double).
static double pow10(int x)
          Deprecated. Moved to Apache SIS MathFunctions.pow10(int).
static int primeNumber(int index)
          Deprecated. No public replacement. MathFunctions.nextPrimeNumber(int) is the closest replacement.
static byte sgn(byte x)
          Deprecated. Moved to Apache SIS MathFunctions.sgn(byte).
static int sgn(double x)
          Deprecated. Moved to Apache SIS MathFunctions.sgn(double).
static int sgn(float x)
          Deprecated. Moved to Apache SIS MathFunctions.sgn(float).
static int sgn(int x)
          Deprecated. Moved to Apache SIS MathFunctions.sgn(int).
static int sgn(long x)
          Deprecated. Moved to Apache SIS MathFunctions.sgn(long).
static short sgn(short x)
          Deprecated. Moved to Apache SIS MathFunctions.sgn(short).
static float toNaN(int index)
          Deprecated. Moved to Apache SIS MathFunctions.toNanFloat(int).
static double xorSign(double value, double sign)
          Deprecated. Moved to Apache SIS MathFunctions.xorSign(double, double).
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SQRT2

@Deprecated
public static final double SQRT2
Deprecated. Moved to Apache SIS MathFunctions.SQRT_2.
The square root of 2, which is 1.4142135623730951.

Since:
3.20
See Also:
Constant Field Values

SIGN_BIT_MASK

@Deprecated
public static final long SIGN_BIT_MASK
Deprecated. No replacement (this is considered internal mechanic).
Bit mask to isolate the sign bit of non-NaN values in a double. For any value other than NaN, the following code evaluate to 0 if the given value is positive:
Double.doubleToRawLongBits(value) & SIGN_BIT_MASK;
Note that this idiom differentiates positive zero from negative zero. It should be used only when such difference matter.

Since:
3.20
See Also:
isPositive(double), isNegative(double), Constant Field Values
Method Detail

magnitude

@Deprecated
public static double magnitude(double... vector)
Deprecated. Moved to Apache SIS MathFunctions.magnitude(double[]).

Returns the magnitude of the given vector. This is defined by:
sqrt(vector[0]² + vector[1]² + … + vector[length-1]²)

Implementation note
In the special case where only one element is different than zero, this method returns directly the absolute value of that element without computing sqrt(v²), in order to avoid rounding error. This special case has been implemented because this method is often invoked for computing the length of offset vectors, typically aligned with the axes of a Cartesian coordinate system.

Parameters:
vector - The vector for which to compute the magnitude.
Returns:
The magnitude of the given vector.
Since:
3.09
See Also:
Math.hypot(double, double)

pow10

@Deprecated
public static double pow10(double x)
Deprecated. Moved to Apache SIS MathFunctions.pow10(double).

Computes 10 raised to the power of x. This method delegates to pow10((int) x) if x is an integer, or to Math.pow(10, x) otherwise.

Parameters:
x - The exponent.
Returns:
10 raised to the given exponent.
See Also:
pow10(int), Math.pow(double, double)

pow10

@Deprecated
public static double pow10(int x)
Deprecated. Moved to Apache SIS MathFunctions.pow10(int).

Computes 10 raised to the power of x. This method tries to be slightly more accurate than Math.pow(10,x), sometime at the cost of performance.

The Math.pow(10,x) method doesn't always return the closest IEEE floating point representation. More accurate calculations are slower and usually not necessary, but the base 10 is a special case since it is used for scaling axes or formatting human-readable output, in which case the precision may matter.

Parameters:
x - The exponent.
Returns:
10 raised to the given exponent.

atanh

@Deprecated
public static double atanh(double x)
Deprecated. Moved to Apache SIS MathFunctions.atanh(double).

Returns the inverse hyperbolic tangent of the given value. This is the inverse of the tanh method. The range of input values is [-1…1]. Special cases:

  • For x = NaN, this method returns NaN.
  • For x = -1, this method returns negative infinity.
  • For x = +1, this method returns positive infinity.
  • Parameters:
    x - The value for which to compute the inverse hyperbolic tangent.
    Returns:
    The inverse hyperbolic tangent of the given value.
    Since:
    3.20
    See Also:
    Math.tanh(double)

    isPositive

    @Deprecated
    public static boolean isPositive(double value)
    Deprecated. Moved to Apache SIS MathFunctions.isPositive(double).

    Returns true if the given value is positive, excluding negative zero. Special cases:

    As seen from the above cases, this method distinguishes positive zero from negative zero. The handling of zero values is the difference between invoking isPositive(double) and testing if (value >= 0).

    Parameters:
    value - The value to test.
    Returns:
    true if the given value is positive, excluding negative zero.
    Since:
    3.20

    isNegative

    @Deprecated
    public static boolean isNegative(double value)
    Deprecated. Moved to Apache SIS MathFunctions.isNegative(double).

    Returns true if the given value is negative, including negative zero. Special cases:

    As seen from the above cases, this method distinguishes positive zero from negative zero. The handling of zero values is the difference between invoking isNegative(double) and testing if (value < 0).

    Parameters:
    value - The value to test.
    Returns:
    true if the given value is negative, including negative zero.
    Since:
    3.20

    isSameSign

    @Deprecated
    public static boolean isSameSign(double v1,
                                                double v2)
    Deprecated. Moved to Apache SIS MathFunctions.isSameSign(double, double).

    Returns true if the given values have the same sign, differentiating positive and negative zeros. Special cases:

    Parameters:
    v1 - The first value.
    v2 - The second value, to compare the sign with the first value.
    Returns:
    true if the given values are not NaN and have the same sign.
    Since:
    3.20
    See Also:
    Math.signum(double)

    sgn

    @Deprecated
    public static int sgn(double x)
    Deprecated. Moved to Apache SIS MathFunctions.sgn(double).

    Returns the sign of x. This method returns -1 if x is negative, 0 if x is zero or NaN and +1 if x is positive.

    Parameters:
    x - The number from which to get the sign.
    Returns:
    +1 if x is positive, -1 if negative, or 0 otherwise.
    See Also:
    Math.signum(double)

    sgn

    @Deprecated
    public static int sgn(float x)
    Deprecated. Moved to Apache SIS MathFunctions.sgn(float).

    Returns the sign of x. This method returns -1 if x is negative, 0 if x is zero or NaN and +1 if x is positive.

    Parameters:
    x - The number from which to get the sign.
    Returns:
    +1 if x is positive, -1 if negative, or 0 otherwise.
    See Also:
    Math.signum(float)

    sgn

    @Deprecated
    public static int sgn(long x)
    Deprecated. Moved to Apache SIS MathFunctions.sgn(long).

    Returns the sign of x. This method returns -1 if x is negative, 0 if x is zero and +1 if x is positive.

    Parameters:
    x - The number from which to get the sign.
    Returns:
    +1 if x is positive, -1 if negative, or 0 otherwise.

    sgn

    @Deprecated
    public static int sgn(int x)
    Deprecated. Moved to Apache SIS MathFunctions.sgn(int).

    Returns the sign of x. This method returns -1 if x is negative, 0 if x is zero and +1 if x is positive.

    Parameters:
    x - The number from which to get the sign.
    Returns:
    +1 if x is positive, -1 if negative, or 0 otherwise.

    sgn

    @Deprecated
    public static short sgn(short x)
    Deprecated. Moved to Apache SIS MathFunctions.sgn(short).

    Returns the sign of x. This method returns -1 if x is negative, 0 if x is zero and +1 if x is positive.

    Parameters:
    x - The number from which to get the sign.
    Returns:
    +1 if x is positive, -1 if negative, or 0 otherwise.

    sgn

    @Deprecated
    public static byte sgn(byte x)
    Deprecated. Moved to Apache SIS MathFunctions.sgn(byte).

    Returns the sign of x. This method returns -1 if x is negative, 0 if x is zero and +1 if x is positive.

    Parameters:
    x - The number from which to get the sign.
    Returns:
    +1 if x is positive, -1 if negative, or 0 otherwise.

    xorSign

    @Deprecated
    public static double xorSign(double value,
                                            double sign)
    Deprecated. Moved to Apache SIS MathFunctions.xorSign(double, double).

    Returns the first floating-point argument with the sign reversed if the second floating-point argument is negative. This method is similar to Math.copySign(value, sign) except that the sign is combined with an exclusive or operation instead than being copied.

    This method computes the same result than the formula below (using only standard functions from Math) except that zeros and Double.NaN values for the sign argument are treated as a positive or negative numbers.

    return magnitude * signum(sign);

    Parameters:
    value - The parameter providing the value that may need a sign change.
    sign - The parameter providing the sign to xor with the value.
    Returns:
    The provided value with its sign reversed if the sign parameter is negative.
    Since:
    3.00
    See Also:
    Math.copySign(double, double)

    adjacentForType

    public static double adjacentForType(Class<? extends Number> type,
                                         double value,
                                         int amount)
                                  throws IllegalArgumentException
    Returns the number adjacent to the given value, as one of the nearest representable numbers of the given type. First this method selects the nearest adjacent value in the direction of positive infinity if amount is positive, or in the direction of negative infinity if amount is negative. Then this operation is repeated as many time as the absolute value of amount. More specifically:

    Parameters:
    type - The type. Should be the class of Double, Float, Long, Integer, Short or Byte.
    value - The number for which to find an adjacent number.
    amount - -1 to return the previous representable number, +1 to return the next representable number, or a multiple of the above.
    Returns:
    One of previous or next representable number as a double.
    Throws:
    IllegalArgumentException - if type is not one of supported types.

    toNaN

    @Deprecated
    public static float toNaN(int index)
                       throws IndexOutOfBoundsException
    Deprecated. Moved to Apache SIS MathFunctions.toNanFloat(int).

    Returns a NaN number for the specified index. Valid NaN numbers have bit fields ranging from 0x7f800001 through 0x7fffffff or 0xff800001 through 0xffffffff. The standard Float.NaN has bit fields 0x7fc00000. See Float.intBitsToFloat(int) for more details on NaN bit values.

    Tip: if the caller needs to ensure that the index is never out of bounds, he can set the parameter value to index % 0x200000.

    Parameters:
    index - The index, from -2097152 to 2097151 inclusive.
    Returns:
    One of the legal NaN values as a float.
    Throws:
    IndexOutOfBoundsException - if the specified index is out of bounds.
    See Also:
    Float.intBitsToFloat(int)

    primeNumber

    @Deprecated
    public static int primeNumber(int index)
                           throws IndexOutOfBoundsException
    Deprecated. No public replacement. MathFunctions.nextPrimeNumber(int) is the closest replacement.

    Returns the ith prime number. This method returns (2, 3, 5, 7, 11...) for index (0, 1, 2, 3, 4, ...). This method is designed for relatively small prime numbers only; don't use it for large values.

    Parameters:
    index - The prime number index, starting at index 0 for prime number 2.
    Returns:
    The prime number at the specified index.
    Throws:
    IndexOutOfBoundsException - if the specified index is too large.
    See Also:
    BigInteger.isProbablePrime(int)

    divisors

    @Deprecated
    public static int[] divisors(int number)
    Deprecated. Moved to Apache SIS MathFunctions.divisors(int).

    Returns the divisors of the specified number as positive integers. For any value other than O (which returns an empty array), the first element in the returned array is always 1 and the last element is always the absolute value of number.

    Parameters:
    number - The number for which to compute the divisors.
    Returns:
    The divisors in strictly increasing order.

    commonDivisors

    @Deprecated
    public static int[] commonDivisors(int... numbers)
    Deprecated. Moved to Apache SIS MathFunctions.commonDivisors(int[]).

    Returns the divisors which are common to all the specified numbers.

    Parameters:
    numbers - The numbers for which to compute the divisors.
    Returns:
    The divisors common to all the given numbers, in strictly increasing order.
    Since:
    3.15


    Copyright © 2009-2013 Geotoolkit.org. All Rights Reserved.