Miscellaneous scalar math functions. More...
Functions | |
template<class Type > | |
Type | Abs (Type x) |
Absolute value. | |
template<class Type > | |
Type | Mod (Type j, Type k) |
j modulo k. | |
template<class Type > | |
Type | PosMod (Type j, Type k) |
Positive wing of j modulo k. | |
Real | Floor (Real x) |
Floor function. | |
Real | Ceiling (Real x) |
Ceiling function. | |
Real | Sqrt (Real x) |
Square root. | |
Real | Pow (Real x, Real y) |
x to the power of y. | |
template<class Type > | |
Type | Log (Type x) |
Log of x to the base E. | |
template<class Type > | |
Type | Log10 (Type x) |
Log base 10 of x. | |
template<class Type > | |
Type | Atan (Type x) |
Arctangent of x. | |
template<class Type > | |
Type | Atan2 (Type x, Type y) |
Arctangent of ratio expressed as numerator x and denominator y. | |
template<class Type > | |
Type | Sin (Type x) |
Sine of Type x. | |
template<class Type > | |
Type | Cos (Type x) |
Cosine of Type x. | |
Real | unitInterp (Real f, Integer L, Integer U) |
Unit interpolation. | |
Real | linearInterpolate (Integer x, Integer xMin, Integer xMax, Integer yMin, Integer yMax) |
Linear interpolation. | |
Real | Round (Real x) |
Rounding. | |
Integer | RealToRational (Real f, Integer Reference a, Integer Reference b) |
Convert Real value to rational value. |
Miscellaneous scalar math functions.
Type Abs | ( | Type | x ) | [inline] |
Absolute value.
x | Value |
Definition at line 35 of file MathFuns.h.
References Return.
{ Return x < 0 ? -x : x; }
Type Atan | ( | Type | x ) | [inline] |
Arctangent of x.
Note: Type must be a floating point type.
x | Value |
Definition at line 94 of file MathFuns.h.
References Return.
{ Return atan( x ); }
Type Atan2 | ( | Type | x, |
Type | y | ||
) | [inline] |
Arctangent of ratio expressed as numerator x and denominator y.
Note: Type must be a floating point type.
x | Numerator |
y | Denominator |
Definition at line 100 of file MathFuns.h.
References Return.
{ Return atan2( x, y ); }
Ceiling function.
x | Real value |
Definition at line 70 of file MathFuns.h.
References Return.
{ Return ceil( x ); }
Type Cos | ( | Type | x ) | [inline] |
Cosine of Type x.
Note: Type must be a floating point type.
x | Value |
Definition at line 110 of file MathFuns.h.
References Return.
Referenced by Exp().
{ Return cos( x ); }
Floor function.
x | Real value |
Definition at line 66 of file MathFuns.h.
References Return.
Referenced by Round().
{ Return floor( x ); }
Real linearInterpolate | ( | Integer | x, |
Integer | xMin, | ||
Integer | xMax, | ||
Integer | yMin, | ||
Integer | yMax | ||
) | [inline] |
Linear interpolation.
x | Value ranging from xMin to xMax |
xMin | Minimum range of x |
xMax | Maximum range of x |
yMin | Target minimum range |
yMax | Target maximum range |
Definition at line 128 of file MathFuns.h.
References Return.
Referenced by stretch().
Type Log | ( | Type | x ) | [inline] |
Log of x to the base E.
Note: Type must be a floating point type.
x | Value |
Definition at line 84 of file MathFuns.h.
References Return.
{ Return log( x ); }
Type Log10 | ( | Type | x ) | [inline] |
Log base 10 of x.
Note: Type must be a floating point type.
x | Value |
Definition at line 89 of file MathFuns.h.
References Return.
{ Return log( x ) / log (10.0); }
Type Mod | ( | Type | j, |
Type | k | ||
) | [inline] |
j modulo k.
Note: Because of its implementation, Type need not be an integral type.
j | Base of modulo operation |
k | Modulus of modulo operation |
Definition at line 41 of file MathFuns.h.
Referenced by Pitch::invert(), Pitch::operator%(), PitchClass(), List< Type >::rotate(), and SetComplex().
Type PosMod | ( | Type | j, |
Type | k | ||
) | [inline] |
Positive wing of j modulo k.
PosMod performs modulus arithmetic but returns only the positive wing of modulus values. Note: Because of its implementation, Type need not be an integral type.
j | Base of modulo operation |
k | Modulus of modulo operation Note, the result will always be positive. |
Definition at line 53 of file MathFuns.h.
Referenced by cycle(), List< Type >::rotate(), and List< Type >::transpose().
x to the power of y.
x | Base |
y | Exponent |
Definition at line 79 of file MathFuns.h.
References Return.
Referenced by Pitch::hertz().
{ Return pow( x, y ); }
Convert Real value to rational value.
f | Real value |
a | Numerator of resulting rational value |
b | Denominator of resulting rational value |
Convert Real value to rational value.
f | Real value to convert |
a | Integer numerator of rational fraction |
b | Integer denominator of rational fraction |
Definition at line 34 of file Musimat.cpp.
References Abs(), Const, Else, For, If, and Return.
Referenced by Rational::Rational(), and Rhythm::Rhythm().
{ If (f == 0.0) { a = 0; b = 1; Return( 0 ); } Else If (f == 1.0) { a = b = 1; Return( 0 ); } Const Integer count = 3000000; Const Real limit = 0.0000001 /* or try: LDBL_EPSILON * 10000 */; If (f < limit) { a = 1; b = count; Return( 0 ); } a = b = 1; // start off with a ratio of 1/1 Integer i; For (i = 0; i < count; i++) { If ( Abs(Real(a)/Real(b) - f) < limit ) Return i; Else { Real x = Abs( Real(a+1)/Real(b) - f ); Real y = Abs( Real(a)/Real(b+1) - f ); If (x < y) a++; Else b++; } } Return i; // If we get here, we've not converged in the number of cycles available }
Rounding.
x | Value to round |
Definition at line 137 of file MathFuns.h.
References Floor(), and Return.
Referenced by InterpTendency().
Type Sin | ( | Type | x ) | [inline] |
Sine of Type x.
Note: Type must be a floating point type.
x | Value |
Definition at line 105 of file MathFuns.h.
References Return.
Referenced by Exp().
{ Return sin( x ); }
Square root.
x | Real value |
Definition at line 74 of file MathFuns.h.
References Return.
{ Return sqrt( x ); }
Unit interpolation.
f | Fraction, in the range 0<=f<=1.0 |
L | Lower bound of unit interpolation |
U | Upper bound of unit interpolation |
Definition at line 117 of file MathFuns.h.
References Return.
Referenced by InterpTendency().
{ Return( f * ( U - L ) + L ); }