org.geotools.util

## Class XMath

• ```public final class XMath
extends Object```
Simple mathematical functions.
Since:
2.0
Author:
Martin Desruisseaux (IRD)
• ### Field Summary

Fields
Modifier and Type Field and Description
`static double` `LN10`
Deprecated.
Was for `log10(double)` internal usage only.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static int` `countFractionDigits(double value)`
Deprecated.
`static double` ```fixRoundingError(double value, int n)```
Deprecated.
`static int` `getBitCount(Class<?> type)`
Deprecated.
`static double` ```hypot(double x, double y)```
Deprecated.
`static boolean` `isInteger(Class<?> type)`
Deprecated.
`static boolean` `isReal(Class<?> type)`
Deprecated.
`static double` `log10(double x)`
Deprecated.
`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.
`static double` `pow10(int x)`
Deprecated.
`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 Class<?>` `primitiveToWrapper(Class<?> type)`
Deprecated.
`static double` ```rool(Class type, double value, int amount)```
Returns the next or previous representable number.
`static double` ```round(double value, int flu)```
Deprecated.
`static byte` `sgn(byte x)`
Deprecated.
`static int` `sgn(double x)`
Deprecated.
`static int` `sgn(float x)`
Deprecated.
`static int` `sgn(int x)`
Deprecated.
`static int` `sgn(long x)`
Deprecated.
`static short` `sgn(short x)`
Deprecated.
`static float` `toNaN(int index)`
Deprecated.
`static <T> T` ```valueOf(Class<T> type, String value)```
Deprecated.
• ### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

• ### Method Detail

• #### hypot

```@Deprecated
public static double hypot(double x,
double y)```
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.
`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.
`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.
• #### rool

```public static double rool(Class type,
double value,
int amount)
throws 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:
`IllegalArgumentException` - if `type` is not one of supported types.
• #### toNaN

```@Deprecated
public static float toNaN(int index)
throws 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:
`IndexOutOfBoundsException` - if the specified index is out of bounds.
• #### isReal

```@Deprecated
public static boolean isReal(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`.
• #### getBitCount

```@Deprecated
public static int getBitCount(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 Class<?> primitiveToWrapper(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(Class<T> type,
String value)
throws IllegalArgumentException,
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:
`IllegalArgumentException` - if `type` is not a recognized type.
`NumberFormatException` - if the string value is not parseable as a number of the specified type.
Since:
2.4