D:/Projects/dark-oberon.svn/game/sources/kernel/mathlib.h File Reference


Detailed Description

Author:
RadonLabs GmbH, Peter Knut
Date:
2005
Version:
1.0 - Initial.

#include <math.h>
#include <stdlib.h>

Defines

#define PI   (3.1415926535897932384626433832795028841971693993751f)
#define TINY   (0.0000001f)
#define SQRT2   (1.4142135623730950488016887242097f)
#define n_clamp(x, min, max)   (((x) < (min)) ? (min) : (((x) > (max)) ? (max) : (x)))
#define n_max(a, b)   (((a) > (b)) ? (a) : (b))
#define n_min(a, b)   (((a) < (b)) ? (a) : (b))
#define n_abs(a)   (((a) < 0.0f) ? (-(a)) : (a))
#define n_sqr(a)   ((a) * (a))
#define n_sgn(a)   (((a) < 0.0f) ? (-1) : (1))
#define n_deg2rad(d)   (((d) * PI) / 180.0f)
#define n_rad2deg(r)   (((r) * 180.0f) / PI)

Functions

float n_log2 (float f)
float n_acos (float x)
float n_asin (float x)
float n_sqrt (float x)
bool n_fequal (float f0, float f1, float tol)
bool n_fless (float f0, float f1, float tol)
bool n_fgreater (float f0, float f1, float tol)
long n_ftol (float val)
float n_smooth (float new_val, float cur_val, float max_change)
float n_saturate (float val)
int n_irand (int max)
float n_frand ()
float n_frand (float max)
double n_drand ()
double n_drand (double max)
int n_fchop (float f)
int n_fround (float f)
float n_lerp (float x, float y, float l)
float n_normangle (float a)
int n_next_p2 (int a)


Define Documentation

#define n_abs (  )     (((a) < 0.0f) ? (-(a)) : (a))

#define n_clamp ( x,
min,
max   )     (((x) < (min)) ? (min) : (((x) > (max)) ? (max) : (x)))

#define n_deg2rad (  )     (((d) * PI) / 180.0f)

#define n_max ( a,
 )     (((a) > (b)) ? (a) : (b))

#define n_min ( a,
 )     (((a) < (b)) ? (a) : (b))

#define n_rad2deg (  )     (((r) * 180.0f) / PI)

#define n_sgn (  )     (((a) < 0.0f) ? (-1) : (1))

#define n_sqr (  )     ((a) * (a))

#define PI   (3.1415926535897932384626433832795028841971693993751f)

#define SQRT2   (1.4142135623730950488016887242097f)

#define TINY   (0.0000001f)


Function Documentation

float n_acos ( float  x  )  [inline]

acos with value clamping.

float n_asin ( float  x  )  [inline]

asin with value clamping.

double n_drand ( double  max  )  [inline]

Returns a pseudo random number between 0.0 and max.

Parameters:
max Maximal boundary.

double n_drand (  )  [inline]

Returns a pseudo random number between 0.0 and 1.0.

int n_fchop ( float  f  )  [inline]

Convert float to integer.

bool n_fequal ( float  f0,
float  f1,
float  tol 
) [inline]

A fuzzy floating point equality check.

bool n_fgreater ( float  f0,
float  f1,
float  tol 
) [inline]

A fuzzy floating point greater-then check.

bool n_fless ( float  f0,
float  f1,
float  tol 
) [inline]

A fuzzy floating point less-then check.

float n_frand ( float  max  )  [inline]

Returns a pseudo random float number between 0.0f and max.

Parameters:
max Maximal boundary.

float n_frand (  )  [inline]

Returns a pseudo random number between 0.0f and 1.0f.

int n_fround ( float  f  )  [inline]

Rounds float to integer.

long n_ftol ( float  val  )  [inline]

Fast float to int conversion (always truncates). see http://www.stereopsis.com/FPU.html for a discussion. NOTE: This works only on x86 endian machines.

int n_irand ( int  max  )  [inline]

Returns a pseudo random number from interval <0, max).

Parameters:
max Maximal boundary.

float n_lerp ( float  x,
float  y,
float  l 
) [inline]

Linearly interpolates between 2 values: ret = x + l * (y - x).

float n_log2 ( float  f  )  [inline]

log2() function.

int n_next_p2 ( int  a  )  [inline]

Gets the first power of 2 >= given value

float n_normangle ( float  a  )  [inline]

Normalizes an angular value into the range rad(0) to rad(360).

float n_saturate ( float  val  )  [inline]

Saturates a value (clamps between 0.0f and 1.0f)

float n_smooth ( float  new_val,
float  cur_val,
float  max_change 
) [inline]

Smooth a new value towards an old value using a max change value.

float n_sqrt ( float  x  )  [inline]

Safe sqrt.


Generated on Sat Oct 20 14:47:30 2007 for Dark Oberon by  doxygen 1.5.3