libnds
Macros | Functions
math.h File Reference

hardware coprocessor math instructions. More...

#include <nds/ndstypes.h>

Macros

#define f32tofloat(n)   (((float)(n)) / (float)(1 << 12))
 Convert f32 to float.
 
#define f32toint(n)   ((n) / (1 << 12))
 Convert f32 to int.
 
#define floattof32(n)   ((int)((n) * (1 << 12)))
 Convert float to f32.
 
#define inttof32(n)   ((n) * (1 << 12))
 Convert int to f32.
 

Functions

static void crossf32 (int32_t *a, int32_t *b, int32_t *result)
 20.12 fixed point cross product. More...
 
static int32_t div32 (int32_t num, int32_t den)
 Integer divide. More...
 
static void div32_asynch (int32_t num, int32_t den)
 Asynchronous integer divide start. More...
 
static int32_t div32_result (void)
 Asynchronous integer divide result. More...
 
static int32_t div64 (int64_t num, int32_t den)
 Integer 64 bit divide. More...
 
static void div64_asynch (int64_t num, int32_t den)
 Asynchronous integer 64 bit divide start. More...
 
static int32_t div64_result (void)
 Asynchronous integer 64 bit divide result. More...
 
static int32_t divf32 (int32_t num, int32_t den)
 Fixed point divide. More...
 
static void divf32_asynch (int32_t num, int32_t den)
 Asynchronous fixed point divide start. More...
 
static int32_t divf32_result (void)
 Asynchronous fixed point divide result. More...
 
static int32_t dotf32 (int32_t *a, int32_t *b)
 20.12 fixed point dot product. More...
 
ARM_CODE float hw_sqrtf (float x)
 32-bit floating point sqrt More...
 
static int32_t mod32 (int32_t num, int32_t den)
 Integer modulo. More...
 
static void mod32_asynch (int32_t num, int32_t den)
 Asynchronous integer modulo start. More...
 
static int32_t mod32_result (void)
 Asynchronous integer modulo result. More...
 
static int32_t mod64 (int64_t num, int32_t den)
 Integer 64 bit modulo. More...
 
static void mod64_asynch (int64_t num, int32_t den)
 Asynchronous integer 64 bit modulo start. More...
 
static int32_t mod64_result (void)
 Asynchronous integer 64 bit modulo result. More...
 
static int32_t mulf32 (int32_t a, int32_t b)
 Fixed point multiply. More...
 
static void normalizef32 (int32_t *a)
 20.12 fixed point normalize (set magnitude to 1.0 and keep the direction). More...
 
static uint32_t sqrt32 (uint32_t a)
 32-bit integer sqrt. More...
 
static void sqrt32_asynch (uint32_t a)
 Asynchronous 32-bit integer sqrt start. More...
 
static uint32_t sqrt32_result (void)
 Asynchronous 32-bit integer sqrt result. More...
 
static uint32_t sqrt64 (uint64_t a)
 64-bit integer sqrt. More...
 
static void sqrt64_asynch (uint64_t a)
 Asynchronous 64-bit integer sqrt start. More...
 
static uint32_t sqrt64_result (void)
 Asynchronous 64-bit integer sqrt result. More...
 
static int32_t sqrtf32 (int32_t a)
 Fixed point sqrt. More...
 
static void sqrtf32_asynch (int32_t a)
 Asynchronous fixed point sqrt start. More...
 
static int32_t sqrtf32_result (void)
 Asynchronous fixed point sqrt result. More...
 

Detailed Description

hardware coprocessor math instructions.

Function Documentation

◆ crossf32()

static void crossf32 ( int32_t *  a,
int32_t *  b,
int32_t *  result 
)
inlinestatic

20.12 fixed point cross product.

Cross product:

result = A x B

x = Ay * Bz - By * Az
y = Az * Bx - Bz * Ax
z = Ax * By - Bx * Ay
Parameters
aPointer to fixed 3 dimensions vector.
bPointer to fixed 3 dimensions vector.
resultResult pointer to fixed 3x3 matrix

◆ div32()

static int32_t div32 ( int32_t  num,
int32_t  den 
)
inlinestatic

Integer divide.

Parameters
numNumerator.
denDenominator.
Returns
32 bit integer result.

◆ div32_asynch()

static void div32_asynch ( int32_t  num,
int32_t  den 
)
inlinestatic

Asynchronous integer divide start.

Parameters
numNumerator.
denDenominator.

◆ div32_result()

static int32_t div32_result ( void  )
inlinestatic

Asynchronous integer divide result.

Returns
32 bit integer result.

◆ div64()

static int32_t div64 ( int64_t  num,
int32_t  den 
)
inlinestatic

Integer 64 bit divide.

Parameters
num64 bit numerator.
den32 bit denominator.
Returns
32 bit integer result.

◆ div64_asynch()

static void div64_asynch ( int64_t  num,
int32_t  den 
)
inlinestatic

Asynchronous integer 64 bit divide start.

Parameters
num64 bit numerator.
den32 bit denominator.

◆ div64_result()

static int32_t div64_result ( void  )
inlinestatic

Asynchronous integer 64 bit divide result.

Returns
32 bit integer result.

◆ divf32()

static int32_t divf32 ( int32_t  num,
int32_t  den 
)
inlinestatic

Fixed point divide.

Parameters
num20.12 numerator.
den20.12 denominator.
Returns
returns 20.12 result.

◆ divf32_asynch()

static void divf32_asynch ( int32_t  num,
int32_t  den 
)
inlinestatic

Asynchronous fixed point divide start.

Parameters
num20.12 numerator.
den20.12 denominator.

◆ divf32_result()

static int32_t divf32_result ( void  )
inlinestatic

Asynchronous fixed point divide result.

Returns
returns 20.12 result.

◆ dotf32()

static int32_t dotf32 ( int32_t *  a,
int32_t *  b 
)
inlinestatic

20.12 fixed point dot product.

Dot Product:

Result = Ax * Bx + Ay * By + Az * Bz
Parameters
aPointer to fixed 3 dimensions vector.
bPointer to fixed 3 dimensions vector.
Returns
32 bit integer result

◆ hw_sqrtf()

ARM_CODE float hw_sqrtf ( float  x)

32-bit floating point sqrt

Warning
Subnormal floats are treated as if they were zero.
Not safe to call inside an interrupt handler.
Parameters
xValid 32 bit non-negative floating point value.
Returns
32 bit floating point value

◆ mod32()

static int32_t mod32 ( int32_t  num,
int32_t  den 
)
inlinestatic

Integer modulo.

Parameters
numNumerator.
denDenominator.
Returns
32 bit integer remainder.

◆ mod32_asynch()

static void mod32_asynch ( int32_t  num,
int32_t  den 
)
inlinestatic

Asynchronous integer modulo start.

Parameters
numNumerator.
denDenominator.

◆ mod32_result()

static int32_t mod32_result ( void  )
inlinestatic

Asynchronous integer modulo result.

Returns
32 bit integer remainder.

◆ mod64()

static int32_t mod64 ( int64_t  num,
int32_t  den 
)
inlinestatic

Integer 64 bit modulo.

Parameters
num64 bit numerator.
den32 bit denominator.
Returns
returns 32 bit integer remainder.

◆ mod64_asynch()

static void mod64_asynch ( int64_t  num,
int32_t  den 
)
inlinestatic

Asynchronous integer 64 bit modulo start.

Parameters
num64 bit numerator.
den32 bit denominator.

◆ mod64_result()

static int32_t mod64_result ( void  )
inlinestatic

Asynchronous integer 64 bit modulo result.

Returns
returns 32 bit integer remainder.

◆ mulf32()

static int32_t mulf32 ( int32_t  a,
int32_t  b 
)
inlinestatic

Fixed point multiply.

Parameters
a20.12 value.
b20.12 value.
Returns
returns 20.12 result.

◆ normalizef32()

static void normalizef32 ( int32_t *  a)
inlinestatic

20.12 fixed point normalize (set magnitude to 1.0 and keep the direction).

Parameters
aPointer to the vector to normalize.

◆ sqrt32()

static uint32_t sqrt32 ( uint32_t  a)
inlinestatic

32-bit integer sqrt.

Parameters
a32 bit positive integer value.
Returns
32 bit integer result.

◆ sqrt32_asynch()

static void sqrt32_asynch ( uint32_t  a)
inlinestatic

Asynchronous 32-bit integer sqrt start.

Parameters
a32 bit positive integer value.

◆ sqrt32_result()

static uint32_t sqrt32_result ( void  )
inlinestatic

Asynchronous 32-bit integer sqrt result.

Returns
32 bit integer result.

◆ sqrt64()

static uint32_t sqrt64 ( uint64_t  a)
inlinestatic

64-bit integer sqrt.

Parameters
a64 bit positive integer value.
Returns
32 bit integer result.

◆ sqrt64_asynch()

static void sqrt64_asynch ( uint64_t  a)
inlinestatic

Asynchronous 64-bit integer sqrt start.

Parameters
a64 bit positive integer value.

◆ sqrt64_result()

static uint32_t sqrt64_result ( void  )
inlinestatic

Asynchronous 64-bit integer sqrt result.

Returns
32 bit integer result.

◆ sqrtf32()

static int32_t sqrtf32 ( int32_t  a)
inlinestatic

Fixed point sqrt.

Parameters
a20.12 positive value.
Returns
20.12 result.

◆ sqrtf32_asynch()

static void sqrtf32_asynch ( int32_t  a)
inlinestatic

Asynchronous fixed point sqrt start.

Parameters
a20.12 positive value.

◆ sqrtf32_result()

static int32_t sqrtf32_result ( void  )
inlinestatic

Asynchronous fixed point sqrt result.

Returns
20.12 result.