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, Integer Reference, Integer Reference) |
| Convert Real value to rational value. | |
| Type Abs | ( | Type | x | ) | [inline] |
Absolute value.
| x | Value |
Definition at line 35 of file MathFuns.h.
References Return.
00035 { 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.
00094 { 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.
00100 { Return atan2( x, y ); }
Ceiling function.
| x | Real value |
Definition at line 70 of file MathFuns.h.
References Return.
00070 { 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(), and Complex::Exp().
00110 { Return cos( x ); }
Floor function.
| x | Real value |
Definition at line 66 of file MathFuns.h.
References Return.
Referenced by Round().
00066 { 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().
00128 { 00129 Real a = Real( x - xMin) / Real(xMax - xMin); // Real division 00130 Real b = Real( yMax - yMin ); 00131 Return( a * b + yMin ); 00132 }
| 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.
00084 { 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.
00089 { 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().
00041 { 00042 While ( j >= k ) { j = j - k; } 00043 While ( j <= -k ) { j = j + k; } 00044 Return( j ); 00045 }
| 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().
00054 { 00055 While ( j >= k ) { 00056 j = j - k; 00057 } 00058 While ( j < 0 ) { 00059 j = j + k; 00060 } 00061 Return( j ); 00062 }
x to the power of y.
| x | Base | |
| y | Exponent |
Definition at line 79 of file MathFuns.h.
References Return.
Referenced by Pitch::hertz().
00079 { Return pow( x, y ); }
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().
00034 { 00035 If (f == 0.0) { 00036 a = 0; 00037 b = 1; 00038 Return( 0 ); 00039 } Else If (f == 1.0) { 00040 a = b = 1; 00041 Return( 0 ); 00042 } 00043 00044 Const Integer count = 3000000; 00045 Const Real limit = 0.0000001 /* or try: LDBL_EPSILON * 10000 */; 00046 00047 If (f < limit) { 00048 a = 1; 00049 b = count; 00050 Return( 0 ); 00051 } 00052 00053 a = b = 1; // start off with a ratio of 1/1 00054 Integer i; 00055 For (i = 0; i < count; i++) { 00056 If ( Abs(Real(a)/Real(b) - f) < limit ) 00057 Return i; 00058 Else { 00059 Real x = Abs( Real(a+1)/Real(b) - f ); 00060 Real y = Abs( Real(a)/Real(b+1) - f ); 00061 If (x < y) 00062 a++; 00063 Else 00064 b++; 00065 } 00066 } 00067 Return i; // If we get here, we've not converged in the number of cycles available 00068 }
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(), and Complex::Exp().
00105 { Return sin( x ); }
Square root.
| x | Real value |
Definition at line 74 of file MathFuns.h.
References Return.
00074 { 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().
00117 { 00118 Return( f * ( U - L ) + L ); 00119 }
1.4.7