| TGX 1.1.0 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 (const T &a, const T &b)
| Don't know why but faster than fminf() for floats.
template<typename T >
TGX_INLINE T | tgx::max (const T &a, const T &b)
| Don't know why but much faster than fmaxf() for floats.
template<typename T >
TGX_INLINE T | tgx::clamp (const T &v, const T &vmin, const 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 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...

## 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() [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)