Modifier and Type | Class and Description |
---|---|
static class |
MathUtils.ExponentAndMantissa
Class to hold an exponent and mantissa
|
Constructor and Description |
---|
MathUtils() |
Modifier and Type | Method and Description |
---|---|
static MathUtils.ExponentAndMantissa |
frexp(double value)
Implementation of the C
frexp function to break
floating-point number into normalized fraction and power of 2. |
static double |
logSum(double log_a,
double log_b)
Given log(a) and log(b) calculate log(a + b) boils down to log(
exp(log_a) + exp(log_b) ) but this might overflow, so we turn this into
log([exp(log_a - log_c) + exp(log_b - log_c)]exp(log_c)) and we set log_c
== max(log_a,log_b) and so it becomes: LARGE + log(1 + exp(SMALL -
LARGE)) == LARGE + log(1 + SMALL) ~= large the whole idea being to avoid
an overflow (exp(LARGE) == VERY LARGE == overflow)
|
static int |
nextPowerOf2(int n)
Returns the next power of 2 superior to n.
|
public MathUtils()
public static double logSum(double log_a, double log_b)
log_a
- log_b
- public static int nextPowerOf2(int n)
n
- The value to find the next power of 2 abovepublic static MathUtils.ExponentAndMantissa frexp(double value)
frexp
function to break
floating-point number into normalized fraction and power of 2.value
- the value