Ocean
Ocean::Approximation Class Reference

This class implements several numeric function with approximated results but with fast performances. More...

Static Public Member Functions

static uint8_t sqrt (const uint8_t value)
 Returns the square root for values inside range [0, 2^8). More...
 
static uint8_t sqrt (const uint16_t value)
 Returns the square root for values inside range [0, 2^16). More...
 
static uint16_t sqrt (const uint32_t value)
 Returns the square root for values inside range [0, 2^17). More...
 
template<typename T >
static T atan2 (const T y, const T x)
 Returns the approximated arc tangent with an error below one degree. More...
 
template<typename T , bool tHigherAccuracy>
static T exp (T x)
 Returns the approximated exponential function exp(x) = e^x. More...
 

Static Protected Member Functions

static const uint8_t * sqrtLookup8 ()
 Creates a lookup table for the sqrt function with range [0, 255]. More...
 
static const uint8_t * sqrtLookup16 ()
 Creates a lookup table for the sqrt function with range [0, 65,535]. More...
 
static const uint16_t * sqrtLookup17 ()
 Creates a lookup table for the sqrt function with range [0, 131,071]. More...
 

Detailed Description

This class implements several numeric function with approximated results but with fast performances.

Member Function Documentation

◆ atan2()

template<typename T >
static T Ocean::Approximation::atan2 ( const T  y,
const T  x 
)
static

Returns the approximated arc tangent with an error below one degree.

Parameters
yY coordinate value, with range (-infinity, infinity), must not be zero if x is zero
xX coordinate value, with range (-infinity, infinity), must not be zero if y is zero
Returns
Approximated arc tangent in radian, with range [-PI, PI]
Template Parameters
TThe data type of the scalar, either 'float' or 'double'

◆ exp()

template<typename T , bool tHigherAccuracy>
T Ocean::Approximation::exp ( x)
inlinestatic

Returns the approximated exponential function exp(x) = e^x.

This function provides two accuracy modes.
The accuracy is as follows for an x86 CPU, within the value range [-1, 1]:

32 bit floating point values:
Lower accuracy: Median (p50) error: 0.00041, p99 error: 0.00498 Higher accuracy: Median (p50) error: 0.00008, p99 error: 0.00096 64 bit floating point values:
Lower accuracy: Median (p50) error: 0.00041, p99 error: 0.00498 Higher accuracy: Median (p50) error: 0.00003, p99 error: 0.00031
Parameters
xThe value for which exp(x) will be approximated, with range (-infinity, infinity)
Returns
The approximated exponential value
Template Parameters
TData type of the provided value, either 'float' or 'double'
tHigherAccuracyTrue, to approximate exp with higher accuracy; False, to get the lower accuracy

◆ sqrt() [1/3]

static uint8_t Ocean::Approximation::sqrt ( const uint16_t  value)
static

Returns the square root for values inside range [0, 2^16).

A lookup table with 2^16 = 65.536 bytes is used, which will be created before the first usage.

Parameters
valueThe value to return the square root for, with range [0, 65535]
Returns
Rounded square root

◆ sqrt() [2/3]

static uint16_t Ocean::Approximation::sqrt ( const uint32_t  value)
static

Returns the square root for values inside range [0, 2^17).

Beware: No range check will be done for the given value. A lookup table with 2^16 * 2 = 131.072 bytes is used, which will be created before the first usage. Therefore, the resulting value does not have the best accuracy due to the reduces lookup table dimension.

Parameters
valueThe value to return the square root for, with range [0, 131071]
Returns
Rounded square root

◆ sqrt() [3/3]

static uint8_t Ocean::Approximation::sqrt ( const uint8_t  value)
static

Returns the square root for values inside range [0, 2^8).

A lookup table with 2^8 = 256 bytes is used, which will be created before the first usage.

Parameters
valueThe value to return the square root for, with range [0, 255]
Returns
Rounded square root

◆ sqrtLookup16()

static const uint8_t* Ocean::Approximation::sqrtLookup16 ( )
staticprotected

Creates a lookup table for the sqrt function with range [0, 65,535].

Returns
Pointer to the static lookup table

◆ sqrtLookup17()

static const uint16_t* Ocean::Approximation::sqrtLookup17 ( )
staticprotected

Creates a lookup table for the sqrt function with range [0, 131,071].

Returns
Pointer to the static lookup table

◆ sqrtLookup8()

static const uint8_t* Ocean::Approximation::sqrtLookup8 ( )
staticprotected

Creates a lookup table for the sqrt function with range [0, 255].

Returns
Pointer to the static lookup table

The documentation for this class was generated from the following file: