MathInlines Namespace Reference

Contains the math inlines routines. More...


Functions

float Interpolate (float x1, float x2, float ratio)
 Calculates the linear interpolation between two float numbers, given the position between them.
bool isPowerOf2 (int x)
 Tells whether the given positive integer is a perfect power of two or not.
int log2i (int x)
 Calculates the exponent of the maximum exact power of 2 that is less or equal to x.
float log_n (float x, float n)
 Calculates the n-based logarithm of a floating-point number.
int max (int a, int b)
 Calculates fast maximum between two integers numbers.
int min (int a, int b)
 Calculates fast minimum between two integers numbers.
float ms2hz (float ms)
 Calculates the frequency cycle in Hz, given the frequency length in milliseconds.
float ms2samples (float ms, float samplerate)
 Converts milliseconds to number of samples, given the samplerate.


Detailed Description

Contains the math inlines routines.

This namespace is used to avoid name conflicts with standard routines such as max and min.


Function Documentation

float MathInlines::Interpolate float  x1,
float  x2,
float  ratio
[inline]
 

Calculates the linear interpolation between two float numbers, given the position between them.

Parameters:
x1 First value.
x2 Second value.
ratio Normalized position between the two numbers, in the range [0.f; 1.f].
Returns:
Linear interpolation of x1,x2 in the position specified by ratio.

Definition at line 212 of file MathInlines.h.

00212                                                           {
00213     return x1 * (1.f - ratio) + x2 * ratio;
00214 }

bool MathInlines::isPowerOf2 int  x  )  [inline]
 

Tells whether the given positive integer is a perfect power of two or not.

Parameters:
x The positive integer to be checked.
Returns:
true whether x is a perfect power of 2, false otherwise.

Definition at line 146 of file MathInlines.h.

00146                               {
00147     return !(x & (x-1));
00148 }

int MathInlines::log2i int  x  )  [inline]
 

Calculates the exponent of the maximum exact power of 2 that is less or equal to x.

Parameters:
x Value for which the integer logarithm has to be calculated.
Returns:
Integer log2(x).
Remarks:
If x is a perfect power of 2, given the returned value v, 2v == x. Otherwise, the returned value v is the value for which 2v <= x and 2v+1 > x.

Definition at line 189 of file MathInlines.h.

00189                         {
00190     int y = 0;
00191     while(x >>= 1) {++y;}
00192     return y;
00193 }

float MathInlines::log_n float  x,
float  n
[inline]
 

Calculates the n-based logarithm of a floating-point number.

Parameters:
x The value for which the logarithm has to be calculated.
n The base to be used with the logarithm.
Returns:
The logn(x) value.
Remarks:
The computational cost is equivalent to a log10() float operation and a float division, if the given n is const.

Definition at line 169 of file MathInlines.h.

00169                                      {
00170     return (log10(x) / log10(n));
00171 }

int MathInlines::max int  a,
int  b
[inline]
 

Calculates fast maximum between two integers numbers.

Parameters:
a First value.
b Second value.
Returns:
The maximum between the two values.
Remarks:
This function is faster than any comparison operators available for integers numbers and is implemented without branches.
See also:
min(int,int)

Definition at line 131 of file MathInlines.h.

00131                              {
00132     return (a - ((a - b) & ((a - b) >> (sizeof(int) * 8 - 1))));
00133 }

int MathInlines::min int  a,
int  b
[inline]
 

Calculates fast minimum between two integers numbers.

Parameters:
a First value.
b Second value.
Returns:
The minimum between the two values.
Remarks:
This function is faster than any comparison operators available for integers numbers and is implemented without branches.
See also:
max(int,int)

Definition at line 107 of file MathInlines.h.

00107                              {
00108     return (b + ((a - b) & ((a - b) >> (sizeof(int) * 8 - 1))));
00109 }

float MathInlines::ms2hz float  ms  )  [inline]
 

Calculates the frequency cycle in Hz, given the frequency length in milliseconds.

Parameters:
ms Number of milliseconds (ie: 25.13f; 12.f).
Returns:
Frequency cycle in Hz, corresponding to the specified wavelength.
See also:
ms2samples(float,float)

Definition at line 83 of file MathInlines.h.

00083                              {
00084     return (1000.f / ms);
00085 }

float MathInlines::ms2samples float  ms,
float  samplerate
[inline]
 

Converts milliseconds to number of samples, given the samplerate.

Parameters:
ms Number of milliseconds (ie: 25.13f; 12.f).
samplerate Samplerate to be used for the conversion (ie: 44100.f).
Returns:
Number of samples corresponding to ms in the specified samplerate.
See also:
ms2hz(float)

Definition at line 66 of file MathInlines.h.

00066                                                     {
00067     return ((ms / 1000.f) * samplerate);
00068 }


Generated on Mon Jan 15 17:13:41 2007 for "ag-works goodies" by  doxygen 1.4.5