Modifier and Type | Method and Description |
---|---|
static int |
countDecimalFractionDigits(double value)
Counts the fraction digits in the string representation of the specified value.
|
static int[] |
divisors(int number)
Returns the divisors of the specified number as positive integers.
|
static double |
pow10(double x)
Computes 10 raised to the power of x.
|
static double |
pow10(int x)
Computes 10 raised to the power of x.
|
static int |
primeNumber(int index)
Returns the ith prime number.
|
static double |
roundIfAlmostInteger(double value,
int maxULP)
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.
|
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.
|
static float |
toNaN(int index)
Returns a
NaN number for the specified index. |
static double |
trimDecimalFractionDigits(double value,
int maxULP,
int n)
Tries to remove at least
n fraction digits in the decimal representation of the
specified value. |
public static double pow10(double x)
pow10(int)
if x is an integer, or to Math.pow(double, double)
otherwise.x
- The exponent.public static double pow10(int x)
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.
x
- The exponent.public static int sgn(double x)
NaN
and +1 if x is positive.x
- The number from which to get the sign.+1
if x is positive, -1
if negative, or 0 otherwise.Math.signum(double)
public static int sgn(float x)
NaN
and +1 if x is positive.x
- The number from which to get the sign.+1
if x is positive, -1
if negative, or 0 otherwise.Math.signum(float)
public static int sgn(long x)
x
- The number from which to get the sign.+1
if x is positive, -1
if negative, or 0 otherwise.public static int sgn(int x)
x
- The number from which to get the sign.+1
if x is positive, -1
if negative, or 0 otherwise.public static short sgn(short x)
x
- The number from which to get the sign.+1
if x is positive, -1
if negative, or 0 otherwise.public static byte sgn(byte x)
x
- The number from which to get the sign.+1
if x is positive, -1
if negative, or 0 otherwise.public static double roundIfAlmostInteger(double value, int maxULP)
value
- The value to round.maxULP
- The maximal change allowed in ULPs (Unit in the Last Place).value
if it was not close enough to an integer.public static double trimDecimalFractionDigits(double value, int maxULP, int n)
n
fraction digits in the decimal representation of the
specified value. This method tries small changes to value
, by adding or substracting
up to maxULP
(Unit in the Last Place). 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.trimLastDecimalDigits(-61.500000000000014, 12, 4)
returns -61.5
.
value
- The value to fix.maxULP
- The maximal change allowed in ULPs (Unit in the Last Place). A typical value is
4.n
- The minimum amount of fraction digits.value
if there is no small change that
remove at least n
fraction digits.public static int countDecimalFractionDigits(double value)
Double.toString(value)
and counting the number of digits after the decimal separator.value
- The value for which to count the fraction digits.public static float toNaN(int index) throws IndexOutOfBoundsException
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.index
- The index, from -2097152 to 2097151 inclusive.NaN
values as a float.IndexOutOfBoundsException
- if the specified index is out of bounds.Float.intBitsToFloat(int)
public static int primeNumber(int index) throws IndexOutOfBoundsException
index
- The prime number index, starting at index 0 for prime number 2.IndexOutOfBoundsException
- if the specified index is too large.BigInteger.isProbablePrime(int)
public static int[] divisors(int number)
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
.number
- The number for which to compute the divisors.Copyright © 1996–2019 Geotools. All rights reserved.