Melee Modding Library  2.0.0
A C library for modding Super Smash Bros Melee
Data Structures | Macros | Functions
math.h File Reference

Useful math functions. More...

#include "gctypes.h"

Go to the source code of this file.

Data Structures

struct  Point
 Struct containing the coordinates of a point. More...
 

Macros

#define M_PI   3.14159265358f
 
#define M_2PI   6.28318530718f
 
#define M_PI_OVER_2   1.57079632679f
 
#define M_PI_OVER_3   1.047197551f
 
#define M_PI_OVER_4   0.785398163f
 
#define M_PI_OVER_6   0.523598776f
 
#define DEG_TO_RAD(x)   ((x) * 0.01745329251f)
 
#define RAD_TO_DEG(x)   ((x) * 57.2957795131f)
 
#define SIGN(x)   ((x) < 0 ? -1 : 1)
 

Functions

float exp (float x)
 e to the power x More...
 
float log (float x)
 natural log More...
 
float fabs (float x)
 Absolute value of x. More...
 
float recipSqrt (float x)
  1 / sqrt(x) More...
 
float floor (float x)
 Round down value. More...
 
float ceil (float x)
 Round up value. More...
 
s32 imax (s32 a, s32 b)
 Maximum of two integers. More...
 
s32 imin (s32 a, s32 b)
 Minimum of two integers. More...
 
float fmax (float a, float b)
 Maximum of two floating-point values. More...
 
float fmin (float a, float b)
 Minimum of two floating-point values. More...
 
int imod (int a, int b)
 Mod operator for integers. More...
 
float fmod (float a, float b)
 Mod operator for floats. More...
 
s32 ipow (s16 base, u8 exp)
 base raised to the power of exp More...
 
float fpow (float base, u8 exp)
 base raised to the power of exp More...
 
float sqrt (float x)
 Square root of x. More...
 
float sin (float x)
 Sine of x, expressed in degrees. More...
 
float cos (float x)
 Cosine of x, expressed in degrees. More...
 
float tan (float x)
 Tangent of x, expressed in degrees. More...
 
float asin (float x)
 Arc sine of x. More...
 
float acos (float x)
 Arc cosine of x. More...
 
float atan (float x)
 Arc tangent of x. More...
 
float atan2 (float y, float x)
 Compute arc tangent with two parameters. More...
 
float magnitude (Point pt)
 Magnitude of point. More...
 
float distance (Point a, Point b)
 Distance between two points. More...
 
float angle (Point a, Point b)
 Angle between two points. More...
 

Detailed Description

Useful math functions.


Data Structure Documentation

struct Point

Struct containing the coordinates of a point.

Data Fields
float x

X-coordinate of point

float y

Y-coordinate of point

Macro Definition Documentation

#define M_PI   3.14159265358f

approximate value of pi

#define M_2PI   6.28318530718f

approximate value of 2 * pi

#define M_PI_OVER_2   1.57079632679f

approximate value of pi / 2

#define M_PI_OVER_3   1.047197551f

approximate value of pi / 3

#define M_PI_OVER_4   0.785398163f

approximate value of pi / 4

#define M_PI_OVER_6   0.523598776f

approximate value of pi / 6

#define DEG_TO_RAD (   x)    ((x) * 0.01745329251f)

degree to radian conversion

#define RAD_TO_DEG (   x)    ((x) * 57.2957795131f)

radian to degree conversion

#define SIGN (   x)    ((x) < 0 ? -1 : 1)

sign of value

Function Documentation

float exp ( float  x)

e to the power x

Parameters
x- floating-point value
Returns
e raised the power x
float log ( float  x)

natural log

Parameters
x- floating-point value, must be positive
Returns
the natural log of x
float fabs ( float  x)

Absolute value of x.

Parameters
x- floating-point value
Returns
The absolute value of x.
float recipSqrt ( float  x)

1 / sqrt(x)

Parameters
x- floating-point value
Returns
the reciprical square root of x
float floor ( float  x)

Round down value.

Rounds x downward, returning the largest integral value that is not greater than @ x

Parameters
x- floating-point value
Returns
The value of x rounded downward (as a floating-point value)
See also
http://www.cplusplus.com/reference/cmath/floor/
float ceil ( float  x)

Round up value.

Rounds x upward, returning the smallest integral value that is not less than @ x

Parameters
x- floating-point value
Returns
The value of x rounded upward (as a floating-point value)
See also
http://www.cplusplus.com/reference/cmath/floor/
s32 imax ( s32  a,
s32  b 
)

Maximum of two integers.

Parameters
a- 32-bit signed int
b- 32-bit signed int
Returns
The larger value of a and b
s32 imin ( s32  a,
s32  b 
)

Minimum of two integers.

Parameters
a- 32-bit signed int
b- 32-bit signed int
Returns
The smaller value of a and b
float fmax ( float  a,
float  b 
)

Maximum of two floating-point values.

Parameters
a- floating-point value
b- floating-point value
Returns
The larger value of a and b
float fmin ( float  a,
float  b 
)

Minimum of two floating-point values.

Parameters
a- floating-point value
b- floating-point value
Returns
The smaller value of a and b
int imod ( int  a,
int  b 
)

Mod operator for integers.

Parameters
a- signed int
b- signed int
Returns
a mod b
float fmod ( float  a,
float  b 
)

Mod operator for floats.

Parameters
a- floating-point value
b- floating-point value
Returns
a mod b
s32 ipow ( s16  base,
u8  exp 
)

base raised to the power of exp

Parameters
base- 16-bit signed int
exp- 8-bit signed int
Returns
base raised to the power of exp
float fpow ( float  base,
u8  exp 
)

base raised to the power of exp

Parameters
base- floating-point value
exp- 8-bit signed int
Returns
base raised to the power of exp
float sqrt ( float  x)

Square root of x.

Parameters
x- floating-point value
Returns
the square root of x
float sin ( float  x)

Sine of x, expressed in degrees.

Parameters
x- floating-point value in [0, 360)
Returns
Sine of x
float cos ( float  x)

Cosine of x, expressed in degrees.

Parameters
x- floating-point value in [0, 360)
Returns
Cosine of x
float tan ( float  x)

Tangent of x, expressed in degrees.

Parameters
x- floating-point value in [0, 360)
Returns
Tangent of x
float asin ( float  x)

Arc sine of x.

Parameters
x- floating-point value in [-1, +1]
Returns
inverse sine of x, expressed in degress in range [0, 90] and [270, 360)
float acos ( float  x)

Arc cosine of x.

Parameters
x- floating-point value in [-1, +1]
Returns
inverse cosine of x, expressed in degress in range [0, 180]
float atan ( float  x)

Arc tangent of x.

Parameters
x- floating-point value in [0, inf)
Returns
inverse tangent of x, expressed in degress in range [0, 90)
float atan2 ( float  y,
float  x 
)

Compute arc tangent with two parameters.

Returns the arc tangent of y / x, expressed in degrees. To compute the value, the function takes into accout the sign of both arguments in order to determine the quadrant.

Parameters
y- floating-point value
x- floating-point value
Returns
arc tangent of y / x, in interval [0, 360) degrees
See also
http://www.cplusplus.com/reference/cmath/atan2/
http://www.embedded.com/design/other/4216719/Performing-efficient-arctangent-approximation
float magnitude ( Point  pt)

Magnitude of point.

Parameters
pt- Point struct
Returns
The distance of pt from (0,0)
Note
error is within 0.26 degrees
float distance ( Point  a,
Point  b 
)

Distance between two points.

Parameters
a- Point struct
b- Point struct
Returns
The distance between a and b
float angle ( Point  a,
Point  b 
)

Angle between two points.

Parameters
a- Point struct
b- Point struct
Returns
The angle between a and b in [0, 360] degrees