org.geotools.resources
Class XMath

java.lang.Object
  extended byorg.geotools.resources.XMath

public final class XMath
extends java.lang.Object

Simple mathematical functions. Some of these functions will be removed if JavaSoft provide a standard implementation or fix some issues in Bug Parade:

Since:
2.0
Version:
$Id: XMath.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Field Summary
static double LN10
          Natural logarithm of 10.
 
Method Summary
static double cbrt(double x)
          Combute the cubic root of the specified value.
static int countFractionDigits(double value)
          Count the fraction digits in the string representation of the specified value.
static double fixRoundingError(double value, int n)
          Try to remove at least fraction digits in the string representation of the specified value.
static int getBitCount(java.lang.Class type)
          Returns the number of bits used by number of the specified type.
static double hypot(double x, double y)
          Compute the hypotenuse (sqrt(x?+y?)).
static boolean isInteger(java.lang.Class type)
          Returns if the specified is one of integer types.
static boolean isReal(java.lang.Class type)
          Returns if the specified is one of real number types.
static double log10(double x)
          Compute the logarithm in base 10.
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)
          Compute 10 power x.
static double pow10(int x)
          Compute x to the power of 10.
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)
          Change a primitive class to its wrapper (e.g.
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)
          Round 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.
static byte sgn(byte x)
          Returns the sign of x.
static int sgn(double x)
          Returns the sign of x.
static int sgn(float x)
          Returns the sign of x.
static int sgn(int x)
          Returns the sign of x.
static int sgn(long x)
          Returns the sign of x.
static short sgn(short x)
          Returns the sign of x.
 
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
Natural logarithm of 10. Approximately equal to 2.302585.

See Also:
Constant Field Values
Method Detail

cbrt

public static double cbrt(double x)
Combute the cubic root of the specified value. This is method will be removed if RFE 4633024 is implemented.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

hypot

public static double hypot(double x,
                           double y)
Compute the hypotenuse (sqrt(x?+y?)).

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

log10

public static double log10(double x)
Compute the logarithm in base 10. See http://developer.java.sun.com/developer/bugParade/bugs/4074599.html.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

pow10

public static double pow10(double x)
Compute 10 power x.


pow10

public static double pow10(int x)
Compute 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

public static int sgn(double x)
Returns the sign of x. This method returns -1 if x is negative, 0 if x is null or and +1 if x is positive.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

sgn

public static int sgn(float x)
Returns the sign of x. This method returns -1 if x is negative, 0 if x is null or and +1 if x is positive.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

sgn

public static int sgn(long x)
Returns the sign of x. This method returns -1 if x is negative, 0 if x is null and +1 if x is positive.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

sgn

public static int sgn(int x)
Returns the sign of x. This method returns -1 if x is negative, 0 if x is null and +1 if x is positive.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

sgn

public static short sgn(short x)
Returns the sign of x. This method returns -1 if x is negative, 0 if x is null and +1 if x is positive.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

sgn

public static byte sgn(byte x)
Returns the sign of x. This method returns -1 if x is negative, 0 if x is null and +1 if x is positive.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

round

public static double round(double value,
                           int flu)
Round 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 if it was not close enough to an integer.

fixRoundingError

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

Example: returns .

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

countFractionDigits

public static int countFractionDigits(double value)
Count 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 , returns same value.

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

previous

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

To Do:
Remove this method when we will be allowed to use J2SE 1.5.

next

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

See Also:
ChoiceFormat.nextDouble(double)
To Do:
Remove this method when we will be allowed to use J2SE 1.5.

previous

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

See Also:
ChoiceFormat.previousDouble(double)
To Do:
Remove this method when we will be allowed to use J2SE 1.5.

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 is equals to , then this method returns the unchanged. Otherwise, The operation performed depends on the specified :

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 .
Throws:
java.lang.IllegalArgumentException - if is not one of supported types.

isReal

public static boolean isReal(java.lang.Class type)
Returns if the specified is one of real number types. Real number types includes Float and Double.

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

isInteger

public static boolean isInteger(java.lang.Class type)
Returns if the specified is one of integer types. Integer types includes Long, Integer, Short and Byte.

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

getBitCount

public static int getBitCount(java.lang.Class type)
Returns the number of bits used by number of the specified type.

Parameters:
type - The type (may be ).
Returns:
The number of bits, or 0 if unknow.
To Do:
Use the predefined constants when we will be allowed to use J2SE 1.5.

primitiveToWrapper

public static java.lang.Class primitiveToWrapper(java.lang.Class type)
Change a primitive class to its wrapper (e.g. to Double). If the specified class is not a primitive type, then it is returned unchanged.

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


Copyright © GeoTools. All Rights Reserved.