sparrowMath

This file is for fast functions for fixed point numbers like trigonometric functions, square root, etc.

Summary
sparrowMathThis file is for fast functions for fixed point numbers like trigonometric functions, square root, etc.
Functions
spInitMathInitializes the fixed point look up tables for sin, cos, etc.
spSinCalculates the sinus of a fixed point value
spCosCalculates the cosinus of a fixed point value
spTanCalculates the tangent of a fixed point value
spAsinCalculates the arcus sinus of a fixed point value
spAcosCalculates the arcus cosinus of a fixed point value
spSqrtFast square root for fixed point numbers
spUnsave_Small_SqrtThis functions returns the square root of a number between 0 and 1 << SP_SQRT_ACCURACY.
spMinReturns the smallest of 2 numbers.
spMaxReturns the biggest of 2 numbers.
spAtofConverts a string to a Sint32 fixed point number like atof.
spSetRandDoes in fact the same as srand() of the glibc or other implementations.
spRandReturns a pseudo random number.

Functions

spInitMath

PREFIX void spInitMath(void)

Initializes the fixed point look up tables for sin, cos, etc.  Is called by spInitCore.

spSin

PREFIX Sint32 spSin(Sint32 value)

Calculates the sinus of a fixed point value

Parameters

valuefixed point radian value

Returns

Sint32fixed point result

See Also

spCos, spTan

spCos

PREFIX Sint32 spCos(Sint32 value)

Calculates the cosinus of a fixed point value

Parameters

valuefixed point radian value

Returns

Sint32fixed point result

See Also

spSin, spTan

spTan

PREFIX Sint32 spTan(Sint32 value)

Calculates the tangent of a fixed point value

Parameters

valuefixed point radian value

Returns

Sint32fixed point result

See Also

spSin, spCos

spAsin

PREFIX Sint32 spAsin(Sint32 value)

Calculates the arcus sinus of a fixed point value

Parameters

valuefixed point radian value

Returns

Sint32fixed point result.  If the value out of the range (not between -SP_ONE and SP_ONE) zero is returned.  If you want some error handling, do it yourself.

See Also

spAcos

spAcos

PREFIX Sint32 spAcos(Sint32 value)

Calculates the arcus cosinus of a fixed point value

Parameters

valuefixed point radian value

Returns

Sint32fixed point result.  If the value out of the range (not between -SP_ONE and SP_ONE) zero is returned.  If you want some error handling, do it yourself.

See Also

spAsin

spSqrt

PREFIX Sint32 spSqrt (Sint32 n)

Fast square root for fixed point numbers

Parameters

nthe fixed point value to be square rooted

Returns

Sint32square root of n

spUnsave_Small_Sqrt

PREFIX Sint32 spUnsave_Small_Sqrt(Sint32 n)

This functions returns the square root of a number between 0 and 1 << SP_SQRT_ACCURACY.  If you give a number outside this range IT WILL CRASH!  So use spSqrt if you are unsure.  The light calculation uses this function for fast rendering.

Parameters

nas said a fixed point value between 0 and 1 << SP_SQRT_ACCURACY

Returns

Sint32the square root of n. Always keep in mind, that the normal fixed point numbers with shift of SP_ACCURACY may not be compatible to this fixed point numbers with shift of SP_SQRT_ACCURACY!

spMin

PREFIX Sint32 spMin(Sint32 a,
Sint32 b)

Returns the smallest of 2 numbers.  To get the smallest of three and more numbers, use a tree like function call like: spMin(spMin(a,b),c) or spMin(spMin(a,b),spMin(c,d)).

Parameters

a,bnumbers to compare

Returns

Sint32the smaller number.  If the numbers are even, it returns the bigger on.

See Also

spMax

spMax

PREFIX Sint32 spMax(Sint32 a,
Sint32 b)

Returns the biggest of 2 numbers.  To get the biggest of three and more numbers, use a tree like function call like: spMax(spMax(a,b),c) or spMax(spMax(a,b),spMax(c,d)).

Parameters

a,bnumbers to compare

Returns

Sint32the bigger number.  If the numbers are even, it returns the smaller on.

See Also

spMin

spAtof

PREFIX Sint32 spAtof(char *buffer)

Converts a string to a Sint32 fixed point number like atof.  Be careful, it is slow, especially on devices without FPU.  But perfect for loading stuff.

Parameters

bufferstring to convert

Returns

Sint32the fixed point value stored in buffer.  That means, if buffer is “12.3” the fixed point conversion of 12.3 will be saved, which is 806092 and not 12.  ;)

spSetRand

PREFIX void spSetRand(Sint32 seed)

Does in fact the same as srand() of the glibc or other implementations.  It sets the start value of the random function.  However this implementation is deterministic the same on every target, doesn’t matter whether Windows, Linux or a Toaster.

Parameters

seedseed of the Randomness.  Default is 0.

See Also

spRand

spRand

PREFIX Sint32 spRand(void)

Returns a pseudo random number.  Don’t use it for cryptographic stuff.  ;)

Returns

Sint32”random” number between 0 and 2^30-1

See Also

spSetRand

PREFIX void spInitMath(void)
Initializes the fixed point look up tables for sin, cos, etc.
PREFIX Sint32 spSin(Sint32 value)
Calculates the sinus of a fixed point value
PREFIX Sint32 spCos(Sint32 value)
Calculates the cosinus of a fixed point value
PREFIX Sint32 spTan(Sint32 value)
Calculates the tangent of a fixed point value
PREFIX Sint32 spAsin(Sint32 value)
Calculates the arcus sinus of a fixed point value
PREFIX Sint32 spAcos(Sint32 value)
Calculates the arcus cosinus of a fixed point value
PREFIX Sint32 spSqrt (Sint32 n)
Fast square root for fixed point numbers
PREFIX Sint32 spUnsave_Small_Sqrt(Sint32 n)
This functions returns the square root of a number between 0 and 1 << SP_SQRT_ACCURACY.
Accurary of the internal sqrt lookuptable
PREFIX Sint32 spMin(Sint32 a,
Sint32 b)
Returns the smallest of 2 numbers.
PREFIX Sint32 spMax(Sint32 a,
Sint32 b)
Returns the biggest of 2 numbers.
PREFIX Sint32 spAtof(char *buffer)
Converts a string to a Sint32 fixed point number like atof.
PREFIX void spSetRand(Sint32 seed)
Does in fact the same as srand() of the glibc or other implementations.
PREFIX Sint32 spRand(void)
Returns a pseudo random number.
PREFIX void spInitCore(void)
spInitCore initializes SDL, SDL_TTF and other stuff.
1.0f in fixed point
Defines how many bits are used for the decimal place
Close