org.geotools.resources
Class XMath

java.lang.Object
  extended by org.geotools.resources.XMath

public final class XMath
extends java.lang.Object

Simple mathematical functions.

Since:
2.0
Version:
$Id: XMath.java 30640 2008-06-12 17:34:32Z acuster $
Author:
Martin Desruisseaux (IRD)

Field Summary
static double LN10
          Deprecated. Was for log10(double) internal usage only.
 
Method Summary
static int countFractionDigits(double value)
          Deprecated. Moved to XMath.
static double fixRoundingError(double value, int n)
          Deprecated. Moved to XMath.
static int getBitCount(java.lang.Class<?> type)
          Deprecated. Moved to Classes.
static double hypot(double x, double y)
          Deprecated. Replaced by Math.hypot(double, double).
static boolean isInteger(java.lang.Class<?> type)
          Deprecated. Moved to Classes.
static boolean isReal(java.lang.Class<?> type)
          Deprecated. Moved to Classes.
static double log10(double x)
          Deprecated. Replaced by Math.log10(double).
static double next(double f)
          Finds the least double greater than f.
static float next(float f)
          Finds the least float greater than f.
static double pow10(double x)
          Deprecated. Moved to XMath.
static double pow10(int x)
          Deprecated. Moved to XMath.
static double previous(double f)
          Finds the greatest double less than f.
static float previous(float f)
          Finds the greatest float less than f.
static java.lang.Class<?> primitiveToWrapper(java.lang.Class<?> type)
          Deprecated. Moved to Classes.
static double rool(java.lang.Class type, double value, int amount)
          Returns the next or previous representable number.
static double round(double value, int flu)
          Deprecated. Moved to XMath.
static byte sgn(byte x)
          Deprecated. Moved to XMath.
static int sgn(double x)
          Deprecated. Moved to XMath.
static int sgn(float x)
          Deprecated. Moved to XMath.
static int sgn(int x)
          Deprecated. Moved to XMath.
static int sgn(long x)
          Deprecated. Moved to XMath.
static short sgn(short x)
          Deprecated. Moved to XMath.
static float toNaN(int index)
          Deprecated. Moved to XMath.
static
<T> T
valueOf(java.lang.Class<T> type, java.lang.String value)
          Deprecated. Moved to Classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LN10

public static final double LN10
Deprecated. Was for log10(double) internal usage only.
Natural logarithm of 10. Approximately equal to 2.302585.

See Also:
Constant Field Values
Method Detail

hypot

@Deprecated
public static double hypot(double x,
                                      double y)
Deprecated. Replaced by Math.hypot(double, double).

Computes the hypotenuse (sqrt(x²+y²)).


log10

@Deprecated
public static double log10(double x)
Deprecated. Replaced by Math.log10(double).

Computes the logarithm in base 10. See http://developer.java.sun.com/developer/bugParade/bugs/4074599.html.


pow10

@Deprecated
public static double pow10(double x)
Deprecated. Moved to XMath.

Computes 10 power x.


pow10

@Deprecated
public static double pow10(int x)
Deprecated. Moved to XMath.

Computes x to the power of 10. This computation is very fast for small power of 10 but has some rounding error issues (see http://developer.java.sun.com/developer/bugParade/bugs/4358794.html).


sgn

@Deprecated
public static int sgn(double x)
Deprecated. Moved to XMath.

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

See Also:
Math.signum(double)

sgn

@Deprecated
public static int sgn(float x)
Deprecated. Moved to XMath.

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

See Also:
Math.signum(float)

sgn

@Deprecated
public static int sgn(long x)
Deprecated. Moved to XMath.

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


sgn

@Deprecated
public static int sgn(int x)
Deprecated. Moved to XMath.

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


sgn

@Deprecated
public static short sgn(short x)
Deprecated. Moved to XMath.

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


sgn

@Deprecated
public static byte sgn(byte x)
Deprecated. Moved to XMath.

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


round

@Deprecated
public static double round(double value,
                                      int flu)
Deprecated. Moved to XMath.

Rounds the specified value, providing that the difference between the original value and the rounded value is not greater than the specified amount of floating point units. This method can be used for hiding floating point error likes 2.9999999996.

Parameters:
value - The value to round.
flu - The amount of floating point units.
Returns:
The rounded value, of value if it was not close enough to an integer.

fixRoundingError

@Deprecated
public static double fixRoundingError(double value,
                                                 int n)
Deprecated. Moved to XMath.

Tries to remove at least n fraction digits in the string representation of the specified value. This method try small changes to value, by adding or substracting a maximum of 4 ulps. If there is no small change that remove at least n fraction digits, then the value is returned unchanged. This method is used for hiding rounding errors, like in conversions from radians to degrees.

Example: XMath.fixRoundingError(-61.500000000000014, 12) returns -61.5.

Parameters:
value - The value to fix.
n - The minimum amount of fraction digits.
Returns:
The fixed value, or the unchanged value if there is no small change that remove at least n fraction digits.

countFractionDigits

@Deprecated
public static int countFractionDigits(double value)
Deprecated. Moved to XMath.

Counts the fraction digits in the string representation of the specified value. This method is equivalent to a call to Double#toString(value) and counting the number of digits after the decimal separator.


next

public static float next(float f)
Finds the least float greater than f. If NaN, returns same value.


previous

public static float previous(float f)
Finds the greatest float less than f. If NaN, returns same value.


next

public static double next(double f)
Finds the least double greater than f. If NaN, returns same value.

See Also:
ChoiceFormat.nextDouble(double)

previous

public static double previous(double f)
Finds the greatest double less than f. If NaN, returns same value.

See Also:
ChoiceFormat.previousDouble(double)

rool

public static double rool(java.lang.Class type,
                          double value,
                          int amount)
                   throws java.lang.IllegalArgumentException
Returns the next or previous representable number. If amount is equals to 0, then this method returns the value unchanged. Otherwise, The operation performed depends on the specified type:

Parameters:
type - The type. Should be the class of Double, Float, Long, Integer, Short or Byte.
value - The number to rool.
amount - -1 to return the previous representable number, +1 to return the next representable number, or 0 to return the number with no change.
Returns:
One of previous or next representable number as a double.
Throws:
java.lang.IllegalArgumentException - if type is not one of supported types.

toNaN

@Deprecated
public static float toNaN(int index)
                   throws java.lang.IndexOutOfBoundsException
Deprecated. Moved to XMath.

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.

Parameters:
index - The index, from -2097152 to 2097151 inclusive.
Returns:
One of the legal NaN values as a float.
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is out of bounds.

isReal

@Deprecated
public static boolean isReal(java.lang.Class<?> type)
Deprecated. Moved to Classes.

Returns true if the specified type is one of real number types. Real number types includes Float and Double.

Parameters:
type - The type to test (may be null).
Returns:
true if type is the class Float or Double.

isInteger

@Deprecated
public static boolean isInteger(java.lang.Class<?> type)
Deprecated. Moved to Classes.

Returns true if the specified type is one of integer types. Integer types includes Long, Integer, Short and Byte.

Parameters:
type - The type to test (may be null).
Returns:
true if type is the class Long, Integer, Short or Byte.

getBitCount

@Deprecated
public static int getBitCount(java.lang.Class<?> type)
Deprecated. Moved to Classes.

Returns the number of bits used by number of the specified type.

Parameters:
type - The type (may be null).
Returns:
The number of bits, or 0 if unknow.

primitiveToWrapper

@Deprecated
public static java.lang.Class<?> primitiveToWrapper(java.lang.Class<?> type)
Deprecated. Moved to Classes.

Change a primitive class to its wrapper (e.g. double to Double). If the specified class is not a primitive type, then it is returned unchanged.

Parameters:
type - The primitive type (may be null).
Returns:
The type as a wrapper.

valueOf

@Deprecated
public static <T> T valueOf(java.lang.Class<T> type,
                                       java.lang.String value)
                 throws java.lang.IllegalArgumentException,
                        java.lang.NumberFormatException
Deprecated. Moved to Classes.

Converts the specified string into a value object. The value object will be an instance of Boolean, Integer, Double, etc. according the specified type.

Parameters:
type - The requested type.
value - the value to parse.
Returns:
The value object, or null if value was null.
Throws:
java.lang.IllegalArgumentException - if type is not a recognized type.
java.lang.NumberFormatException - if the string value is not parseable as a number of the specified type.
Since:
2.4


Copyright © 1996-2010 Geotools. All Rights Reserved.