| TGX 1.1.3 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Macros | Functions
Misc.h File Reference

Utility/miscellaneous functions used throughout the library. More...

`#include "tgx_config.h"`
`#include <stdint.h>`
`#include <math.h>`
`#include <string.h>`

Go to the source code of this file.

## Macros
#define | TGX_FORCED_INLINE inline
| Force inlining for very small helper functions on compilers that support it. More...
#define | M_PI 3.14159265358979323846
| define Pi in case math.h is not yet included.

## Functions
TGX_INLINE uint16_t | tgx::BigEndian16 (uint16_t v)
| little endian / big endian conversion
template<typename T >
TGX_INLINE void | tgx::swap (T &a, T &b)
| Baby let me swap you one more time...
template<typename T >
TGX_INLINE T | tgx::min (T a, T b)
| Don't know why but faster than fminf() for floats.
template<typename T >
TGX_INLINE T | tgx::max (T a, T b)
| Don't know why but much faster than fmaxf() for floats.
template<typename T >
TGX_INLINE T | tgx::clamp (T v, T vmin, T vmax)
| Template clamp version.
TGX_INLINE float | tgx::roundfp (const float f)
| Rounding for floats.
TGX_INLINE double | tgx::roundfp (const double f)
| Rounding for doubles.
TGX_INLINE uint32_t | tgx::float_as_uint32 (float f)
| Reinterpret the bits of a float as a uint32_t.
TGX_INLINE float | tgx::uint32_as_float (uint32_t u)
| Reinterpret the bits of a uint32_t as a float.
TGX_INLINE int32_t | tgx::safeMultB (int32_t A, int32_t B)
| Return a value smaller or equal to B such that the multiplication by A is safe (no overflow with int32).
TGX_INLINE float | tgx::fast_inv (float x)
| Fast (approximate) computation of 1/x. More...
TGX_INLINE float | tgx::fast_inv_approx (float x)
| Fast (very approximate) computation of 1/x. More...
TGX_INLINE double | tgx::fast_inv (double x)
| Fast (approximate) computation of 1/x. More...
TGX_INLINE float | tgx::precise_sqrt (float x)
| Compute the square root of a float (exact computation).
TGX_INLINE double | tgx::precise_sqrt (double x)
| Compute the square root of a double (exact computation).
TGX_INLINE float | tgx::fast_sqrt (float x)
| Compute a fast approximation of the square root of a float. More...
TGX_INLINE double | tgx::fast_sqrt (double x)
| Compute a fast approximation of the square root of a double.
TGX_INLINE float | tgx::precise_invsqrt (float x)
| Compute the inverse square root of a float (exact computation). More...
TGX_INLINE double | tgx::precise_invsqrt (double x)
| Compute the inverse square root of a double (exact computation).
TGX_INLINE float | tgx::fast_invsqrt (float x)
| Compute a fast approximation of the inverse square root of a float. More...
TGX_INLINE double | tgx::fast_invsqrt (double x)
| Compute a fast approximation of the inverse square root of a float.
TGX_INLINE int32_t | tgx::lfloorf (float x)
| Compute (int32_t)floorf(x). More...
TGX_INLINE float | tgx::tgx_fast_cos_deg_clamped (float deg)
| Fast cosine approximation for an angle expressed in degrees. More...
TGX_INLINE float | tgx::tgx_fast_sin_deg_clamped (float deg)
| Fast sine approximation for an angle expressed in degrees. More...

## Detailed Description

Utility/miscellaneous functions used throughout the library.

## Macro Definition Documentation

## ◆ TGX_FORCED_INLINE

#define TGX_FORCED_INLINE inline

Force inlining for very small helper functions on compilers that support it.

This is used only on hot internal helpers where an out-of-line call would be more expensive than the function body itself.

## Function Documentation

## ◆ fast_inv() [1/2]

TGX_INLINE float tgx::fast_inv | ( | float | x | ) |
| inline

Fast (approximate) computation of 1/x.

Version for float.

Credit Ken Cooke (@joestash)

## ◆ fast_inv_approx()

TGX_INLINE float tgx::fast_inv_approx | ( | float | x | ) |
| inline

Fast (very approximate) computation of 1/x.

Version for float. Use only when speed is more important than accuracy...

## ◆ fast_inv() [2/2]

TGX_INLINE double tgx::fast_inv | ( | double | x | ) |
| inline

Fast (approximate) computation of 1/x.

Version for double.

## ◆ fast_sqrt()

TGX_INLINE float tgx::fast_sqrt | ( | float | x | ) |
| inline

Compute a fast approximation of the square root of a float.

Credit Ken Cooke (@joestash)

## ◆ precise_invsqrt()

TGX_INLINE float tgx::precise_invsqrt | ( | float | x | ) |
| inline

Compute the inverse square root of a float (exact computation).

Credit Ken Cooke (@joestash)

## ◆ fast_invsqrt()

TGX_INLINE float tgx::fast_invsqrt | ( | float | x | ) |
| inline

Compute a fast approximation of the inverse square root of a float.

Credit Ken Cooke (@joestash)

## ◆ lfloorf()

TGX_INLINE int32_t tgx::lfloorf | ( | float | x | ) |
| inline

Compute (int32_t)floorf(x).

Credit Ken Cooke (@joestash)

## ◆ tgx_fast_cos_deg_clamped()

TGX_INLINE float tgx::tgx_fast_cos_deg_clamped | ( | float | deg | ) |
| inline

Fast cosine approximation for an angle expressed in degrees.

value in degrees clamped to `[-180, 180]`. accuracy: mean absolute error `5.05195e-4`, RMS error `5.96683e-4`, maximum absolute error `1.09041e-3`.

## ◆ tgx_fast_sin_deg_clamped()

TGX_INLINE float tgx::tgx_fast_sin_deg_clamped | ( | float | deg | ) |
| inline

Fast sine approximation for an angle expressed in degrees.

value in degrees clamped to `[-180, 180]`. accuracy: mean absolute error `5.05195e-4`, RMS error `5.96683e-4`, maximum absolute error `1.09041e-3`.