Functions

Miscellaneous Math Functions

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.

Detailed Description

Miscellaneous scalar math functions.


Function Documentation

template<class Type >
Type Abs ( Type  x ) [inline]

Absolute value.

Parameters:
xValue

Definition at line 35 of file MathFuns.h.

References Return.

{ Return x < 0 ? -x : x; }
template<class Type >
Type Atan ( Type  x ) [inline]

Arctangent of x.

Note: Type must be a floating point type.

Parameters:
xValue

Definition at line 94 of file MathFuns.h.

References Return.

{ Return atan( x ); }
template<class Type >
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.

Parameters:
xNumerator
yDenominator

Definition at line 100 of file MathFuns.h.

References Return.

{ Return atan2( x, y ); }
Real Ceiling ( Real  x ) [inline]

Ceiling function.

Parameters:
xReal value

Definition at line 70 of file MathFuns.h.

References Return.

{ Return ceil( x ); }
template<class Type >
Type Cos ( Type  x ) [inline]

Cosine of Type x.

Note: Type must be a floating point type.

Parameters:
xValue

Definition at line 110 of file MathFuns.h.

References Return.

Referenced by Exp().

{ Return cos( x ); }
Real Floor ( Real  x ) [inline]

Floor function.

Parameters:
xReal 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.

Parameters:
xValue ranging from xMin to xMax
xMinMinimum range of x
xMaxMaximum range of x
yMinTarget minimum range
yMaxTarget maximum range
Returns:
The interpolated value

Definition at line 128 of file MathFuns.h.

References Return.

Referenced by stretch().

                                                                                                   {
        Real a = Real( x - xMin) / Real(xMax - xMin); // Real division
        Real b = Real( yMax - yMin );
        Return( a * b + yMin );
}
template<class Type >
Type Log ( Type  x ) [inline]

Log of x to the base E.

Note: Type must be a floating point type.

Parameters:
xValue

Definition at line 84 of file MathFuns.h.

References Return.

{ Return log( x ); }
template<class Type >
Type Log10 ( Type  x ) [inline]

Log base 10 of x.

Note: Type must be a floating point type.

Parameters:
xValue

Definition at line 89 of file MathFuns.h.

References Return.

{ Return log( x ) / log (10.0); }
template<class Type >
Type Mod ( Type  j,
Type  k 
) [inline]

j modulo k.

Note: Because of its implementation, Type need not be an integral type.

Parameters:
jBase of modulo operation
kModulus of modulo operation

Definition at line 41 of file MathFuns.h.

References Return, and While.

Referenced by Pitch::invert(), Pitch::operator%(), PitchClass(), List< Type >::rotate(), and SetComplex().

                                                     {
        While ( j >= k ) { j = j - k; }
        While ( j <= -k ) { j = j + k; }
        Return( j );
}
template<class Type >
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.

Parameters:
jBase of modulo operation
kModulus of modulo operation Note, the result will always be positive.

Definition at line 53 of file MathFuns.h.

References Return, and While.

Referenced by cycle(), List< Type >::rotate(), and List< Type >::transpose().

{
        While ( j >= k ) {
                j = j - k; 
        }
        While ( j < 0 ) {
                j = j + k; 
        }
        Return( j );
}
Real Pow ( Real  x,
Real  y 
) [inline]

x to the power of y.

Parameters:
xBase
yExponent

Definition at line 79 of file MathFuns.h.

References Return.

Referenced by Pitch::hertz().

{ Return pow( x, y ); }
Integer RealToRational ( Real  f,
Integer Reference  a,
Integer Reference  b 
)

Convert Real value to rational value.

Parameters:
fReal value
aNumerator of resulting rational value
bDenominator of resulting rational value

Convert Real value to rational value.

Parameters:
fReal value to convert
aInteger numerator of rational fraction
bInteger denominator of rational fraction
Returns:
The number of attempts to determine the rational fraction. If the return value equals the internal count value, then the method did not converge. The values for the numerator and denominator returned are nonetheless the best estimates given the limits. Internal tuning values count and limit are used to control the amount of effort this routine puts into finding the best estimate of the rational fractional equivalent.

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
}
Real Round ( Real  x ) [inline]

Rounding.

Parameters:
xValue to round
Returns:
Rounded value

Definition at line 137 of file MathFuns.h.

References Floor(), and Return.

Referenced by InterpTendency().

                            { 
        Return( Floor( x + 0.5 ) );
}
template<class Type >
Type Sin ( Type  x ) [inline]

Sine of Type x.

Note: Type must be a floating point type.

Parameters:
xValue

Definition at line 105 of file MathFuns.h.

References Return.

Referenced by Exp().

{ Return sin( x ); }
Real Sqrt ( Real  x ) [inline]

Square root.

Parameters:
xReal value

Definition at line 74 of file MathFuns.h.

References Return.

{ Return sqrt( x ); }
Real unitInterp ( Real  f,
Integer  L,
Integer  U 
) [inline]

Unit interpolation.

Parameters:
fFraction, in the range 0<=f<=1.0
LLower bound of unit interpolation
UUpper bound of unit interpolation
Returns:
The interpolated value

Definition at line 117 of file MathFuns.h.

References Return.

Referenced by InterpTendency().

                                                       {
        Return( f * ( U - L ) + L );
}