java.lang.Object
io.jenetics.internal.math.Basics
This object contains mathematical helper functions.
- Since:
- 1.0
- Version:
- 5.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
divide
(double[] values, double divisor) Component wise division of the given double array.static boolean
isMultiplicationSave
(int a, int b) static double[]
normalize
(double[] values) Normalize the given double array, so that it sums to one.static double[]
normalize
(long[] values) static long
pow
(long b, long e) Binary exponentiation algorithm.static long
ulpDistance
(double a, double b) Return the ULP distance of the given two double values.static long
ulpPosition
(double a) Calculating the ULP position of a double number.
-
Method Details
-
normalize
Normalize the given double array, so that it sums to one. The normalization is performed in place and the samevalues
are returned.- Parameters:
values
- the values to normalize.- Returns:
- the
values
array. - Throws:
NullPointerException
- if the given double array isnull
.
-
normalize
-
divide
Component wise division of the given double array.- Parameters:
values
- the double values to divide.divisor
- the divisor.- Throws:
NullPointerException
- if the given double array isnull
.
-
pow
Binary exponentiation algorithm.- Parameters:
b
- the base number.e
- the exponent.- Returns:
b^e
.
-
isMultiplicationSave
-
ulpDistance
Return the ULP distance of the given two double values.- Parameters:
a
- first double.b
- second double.- Returns:
- the ULP distance.
- Throws:
ArithmeticException
- if the distance doesn't fit in a long value.
-
ulpPosition
Calculating the ULP position of a double number.double a = 0.0; for (int i = 0; i < 10; ++i) { a = Math.nextAfter(a, Double.POSITIVE_INFINITY); } for (int i = 0; i < 19; ++i) { a = Math.nextAfter(a, Double.NEGATIVE_INFINITY); System.out.println( a + "\t" + ulpPosition(a) + "\t" + ulpDistance(0.0, a) ); }
4.4E-323 9 9 4.0E-323 8 8 3.5E-323 7 7 3.0E-323 6 6 2.5E-323 5 5 2.0E-323 4 4 1.5E-323 3 3 1.0E-323 2 2 4.9E-324 1 1 0.0 0 0 -4.9E-324 -1 1 -1.0E-323 -2 2 -1.5E-323 -3 3 -2.0E-323 -4 4 -2.5E-323 -5 5 -3.0E-323 -6 6 -3.5E-323 -7 7 -4.0E-323 -8 8 -4.4E-323 -9 9
- Parameters:
a
- the double number.- Returns:
- the ULP position.
-