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 doubleclamp(double v, double lo, double hi) Clamping a value between a pair of boundary values.static voiddivide(double[] values, double divisor) Component wise division of the given double array.static booleanisMultiplicationSave(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 longpow(long b, long e) Binary exponentiation algorithm.static longulpDistance(double a, double b) Return the ULP distance of the given two double values.static longulpPosition(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 samevaluesare returned.- Parameters:
values- the values to normalize.- Returns:
- the
valuesarray. - 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
-
clamp
Clamping a value between a pair of boundary values. Note: using clamp with floating point numbers may give unexpected results if one of the values isNaN.- Parameters:
v- the value to clamplo- the lower bound.hi- the upper bound.- Returns:
- The clamped value:
lo if v < lohi if hi < votherwise, v
-
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.The code fragment above will create the following output: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.
-