org.openimaj.math.util

## Class MathUtils

• ```public class MathUtils
extends Object```
A collection of maths functions not available anywhere else ive seen
Author:
Sina Samangooei (ss@ecs.soton.ac.uk)
• ### Nested Class Summary

Nested Classes
Modifier and Type Class and Description
`static class ` `MathUtils.ExponentAndMantissa`
Class to hold an exponent and mantissa
• ### Constructor Summary

Constructors
Constructor and Description
`MathUtils()`
• ### Method Summary

All Methods
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.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### MathUtils

`public MathUtils()`
• ### Method Detail

• #### logSum

```public 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)
Parameters:
`log_a` -
`log_b` -
Returns:
log(a+b)
• #### nextPowerOf2

`public static int nextPowerOf2(int n)`
Returns the next power of 2 superior to n.
Parameters:
`n` - The value to find the next power of 2 above
Returns:
The next power of 2
• #### frexp

`public static MathUtils.ExponentAndMantissa frexp(double value)`
Implementation of the C `frexp` function to break floating-point number into normalized fraction and power of 2.
Parameters:
`value` - the value
Returns:
the exponent and mantissa of the input value