Math module

Contents

Math related stuff.

Files

file bn_fixed.h
file bn_fixed_fwd.h
file bn_fixed_point.h
file bn_fixed_rect.h
file bn_fixed_size.h
file bn_math.h
file bn_point.h
file bn_power_of_two.h
file bn_reciprocal_lut.h
file bn_rect.h
file bn_rule_of_three_approximation.h
file bn_sin_lut.h
file bn_size.h

Classes

template<int Precision>
struct bn::hash<fixed_t<Precision>>
Hash support for fixed_t.
template<int Precision>
class bn::fixed_t
Poor man's float.
class bn::fixed_point
Defines a two-dimensional point using fixed point precision.
template<>
struct bn::hash<fixed_point>
Hash support for fixed_point.
class bn::fixed_rect
Defines a two-dimensional rectangle using fixed point precision.
template<>
struct bn::hash<fixed_rect>
Hash support for fixed_rect.
class bn::fixed_size
Defines the size of a two-dimensional object using fixed point precision.
template<>
struct bn::hash<fixed_size>
Hash support for fixed_size.
class bn::point
Defines a two-dimensional point using integer precision.
template<>
struct bn::hash<point>
Hash support for point.
class bn::rect
Defines a two-dimensional rectangle using integer precision.
template<>
struct bn::hash<rect>
Hash support for rect.
class bn::rule_of_three_approximation
Approximates a rule of three cross-multiplication (x = (value * multiplier) / divisor).
class bn::size
Defines the size of a two-dimensional object using integer precision.
template<>
struct bn::hash<size>
Hash support for size.

Functions

template<typename Type>
auto abs(Type value) -> Type constexpr
Returns the absolute value of the given value.
auto sqrt(int value) -> int constexpr
Returns the integer square root of the given value.
template<int Precision>
auto sqrt(fixed_t<Precision> value) -> fixed_t<(Precision+1)/2> constexpr
Returns the fixed point square root of the given value.
template<typename Type>
auto newton_raphson_sqrt(Type value) -> Type constexpr
Returns the square root of the given value using the Newton–Raphson method.
auto sin(fixed_t<16> angle) -> fixed constexpr
Calculates the sine value of an angle.
auto degrees_sin(fixed degrees_angle) -> fixed constexpr
Calculates the sine value of an angle in degrees.
auto lut_sin(int lut_angle) -> fixed constexpr
Calculates the sine value of an angle using a LUT.
auto degrees_lut_sin(fixed degrees_angle) -> fixed constexpr
Calculates the sine value of an angle in degrees using a LUT.
auto cos(fixed_t<16> angle) -> fixed constexpr
Calculates the cosine value of an angle.
auto degrees_cos(fixed degrees_angle) -> fixed constexpr
Calculates the cosine value of an angle in degrees.
auto lut_cos(int lut_angle) -> fixed constexpr
Calculates the cosine value of an angle using a LUT.
auto degrees_lut_cos(fixed degrees_angle) -> fixed constexpr
Calculates the cosine value of an angle in degrees using a LUT.
auto atan2(int y, int x) -> fixed_t<16>
Computes the arc tangent of y/x using the signs of arguments to determine the correct quadrant.
auto degrees_atan2(int y, int x) -> fixed
Computes the arc tangent of y/x using the signs of arguments to determine the correct quadrant.
auto lut_reciprocal(int lut_value) -> fixed_t<20> constexpr
Calculates the reciprocal of a value using a LUT.
template<typename Type>
auto power_of_two(Type value) -> bool constexpr
Indicates if the given value is a power of two or not.
auto calculate_reciprocal_lut_value(int lut_value) -> fixed_t<20> constexpr
Calculates the value to store in reciprocal_lut for the given value.
auto calculate_sin_lut_value(int lut_angle) -> int constexpr
Calculates the value to store in sin_lut for the given angle.

Variables

int reciprocal_lut_size constexpr
Reciprocal LUT size.
const array<fixed_t<20>, reciprocal_lut_size>& reciprocal_lut
Reciprocal LUT.
int sin_lut_size constexpr
Size of the sine LUT of 16bit values in 4.12 format.
const array<int16_t, sin_lut_size>& sin_lut
Sine LUT of 16bit values in 4.12 format.

Function documentation

#include <bn_math.h>
template<typename Type>
Type abs(Type value) constexpr

Returns the absolute value of the given value.

int sqrt(int value) constexpr
#include <bn_math.h>

Returns the integer square root of the given value.

#include <bn_math.h>
template<int Precision>
fixed_t<(Precision+1)/2> sqrt(fixed_t<Precision> value) constexpr

Returns the fixed point square root of the given value.

See https://github.com/JoaoBaptMG/gba-modern/blob/master/source/math/fixedmath.hpp

#include <bn_math.h>
template<typename Type>
Type newton_raphson_sqrt(Type value) constexpr

Returns the square root of the given value using the Newton–Raphson method.

See https://en.wikipedia.org/wiki/Newton%27s_method#Square_root

fixed sin(fixed_t<16> angle) constexpr
#include <bn_math.h>

Calculates the sine value of an angle.

Parameters
angle Angle (2π = 1).
Returns Sine value in the range [-1, 1].

fixed degrees_sin(fixed degrees_angle) constexpr
#include <bn_math.h>

Calculates the sine value of an angle in degrees.

Parameters
degrees_angle Angle in degrees.
Returns Sine value in the range [-1, 1].

fixed lut_sin(int lut_angle) constexpr
#include <bn_math.h>

Calculates the sine value of an angle using a LUT.

Parameters
lut_angle Angle in the range [0, 2048].
Returns Sine value in the range [-1, 1].

fixed degrees_lut_sin(fixed degrees_angle) constexpr
#include <bn_math.h>

Calculates the sine value of an angle in degrees using a LUT.

Parameters
degrees_angle Angle in degrees in the range [0, 360].
Returns Sine value in the range [-1, 1].

fixed cos(fixed_t<16> angle) constexpr
#include <bn_math.h>

Calculates the cosine value of an angle.

Parameters
angle Angle (2π = 1).
Returns Cosine value in the range [-1, 1].

fixed degrees_cos(fixed degrees_angle) constexpr
#include <bn_math.h>

Calculates the cosine value of an angle in degrees.

Parameters
degrees_angle Angle in degrees.
Returns Cosine value in the range [-1, 1].

fixed lut_cos(int lut_angle) constexpr
#include <bn_math.h>

Calculates the cosine value of an angle using a LUT.

Parameters
lut_angle Angle in the range [0, 2048].
Returns Cosine value in the range [-1, 1].

fixed degrees_lut_cos(fixed degrees_angle) constexpr
#include <bn_math.h>

Calculates the cosine value of an angle in degrees using a LUT.

Parameters
degrees_angle Angle in degrees in the range [0, 360].
Returns Cosine value in the range [-1, 1].

fixed_t<16> atan2(int y, int x)
#include <bn_math.h>

Computes the arc tangent of y/x using the signs of arguments to determine the correct quadrant.

Parameters
y Vertical value in the range [-32767, 32767].
x Horizontal value in the range [-32767, 32767].
Returns Arc tangent of y/x in the range [-0.5, 0.5] (2π = 1).

fixed degrees_atan2(int y, int x)
#include <bn_math.h>

Computes the arc tangent of y/x using the signs of arguments to determine the correct quadrant.

Parameters
y Vertical value in the range [-32767, 32767].
x Horizontal value in the range [-32767, 32767].
Returns Arc tangent of y/x in degrees in the range [-180, 180].

fixed_t<20> lut_reciprocal(int lut_value) constexpr
#include <bn_math.h>

Calculates the reciprocal of a value using a LUT.

Parameters
lut_value Value in the range [1, 1024].
Returns Reciprocal of the given value (1 / value).

template<typename Type>
bool power_of_two(Type value) constexpr

Indicates if the given value is a power of two or not.

fixed_t<20> calculate_reciprocal_lut_value(int lut_value) constexpr

Calculates the value to store in reciprocal_lut for the given value.

Parameters
lut_value reciprocal_lut value (>= 1).
Returns Reciprocal of the given value (1 / value).

int calculate_sin_lut_value(int lut_angle) constexpr

Calculates the value to store in sin_lut for the given angle.

Parameters
lut_angle sin_lut angle (360 degrees = 65536).
Returns Sine value in the range [-4096, 4096].

Variable documentation

int reciprocal_lut_size constexpr

Reciprocal LUT size.

const array<fixed_t<20>, reciprocal_lut_size>& reciprocal_lut

Reciprocal LUT.

int sin_lut_size constexpr

Size of the sine LUT of 16bit values in 4.12 format.

const array<int16_t, sin_lut_size>& sin_lut

Sine LUT of 16bit values in 4.12 format.