C12Adapter Opensource C++ Interface
MMath Class Reference

MMath is derived from MObject, and it only has static properties and methods. More...

Inheritance diagram for MMath:

Static Public Member Functions

static double GetPI ()
 Get the PI constant.
 
static double GetE ()
 Get the E constant.
 
static MVariant Min (const MVariant &v1, const MVariant &v2)
 Returns the smaller of the two two given parameters. More...
 
static MVariant Max (const MVariant &v1, const MVariant &v2)
 Returns the bigger of the two given parameters. More...
 
static MVariant Abs (const MVariant &num)
 Returns the absolute value of the given parameter. More...
 
static double Floor (double num)
 Returns the closest from the left integer number to a given double precision floating point number. More...
 
static double Ceil (double num)
 Returns the closest from the right integer number to a given double precision floating point number. More...
 
static double Round0 (double val)
 Round the floating point value to the nearest whole number. More...
 
static double Round (double val, int numDecimalPlaces=0)
 Round the floating point number to the given decimal digits after comma. More...
 
static int RoundUpToPowerOfTwo (int x)
 Round a given integer number to the nearest power of two, which is bigger or equal to the initial number. More...
 
static unsigned RoundUpToPowerOfTwo (unsigned x)
 Round a given unsigned integer number to the nearest power of two, which is bigger or equal to the initial number. More...
 
static double Sqrt (double arg)
 Returns the square root of the given parameter. More...
 
static double Pow10 (int power)
 Facility function that efficiently returns the integer power of ten. More...
 
static double Pow2 (int power)
 Facility function that efficiently returns the integer power of two. More...
 
static double Pow (double x, double y)
 Value of x raised into power y. More...
 
static double Exp (double num)
 Returns the base-e exponential function of num, which is e raised to the power num: e^num. More...
 
static double Log (double num)
 Returns the natural logarithm of the number. More...
 
static double Log10 (double num)
 Returns the common (base-10) logarithm of num. More...
 
static double Sin (double num)
 Returns the sine of an angle of num radians. More...
 
static double Cos (double num)
 Returns the cosine of an angle of num radians. More...
 
static double Tan (double num)
 Returns the tangent of an angle of num radians. More...
 
static double Asin (double num)
 Returns the principal value of the arc sine of num, expressed in radians. More...
 
static double Acos (double num)
 Returns the principal value of the arc cosine of num, expressed in radians. More...
 
static double Atan (double num)
 Returns the principal value of the arc tangent of x, expressed in radians. More...
 
static int Rand ()
 Pseudo-random integer number in range 0 . More...
 
static unsigned RandomInRange (unsigned minimum, unsigned maximum)
 Pseudo-random unsigned number within a given inclusive range. More...
 
static double RandomFloat ()
 Returns a pseudo-random double precision floating point number in range [0.0 to 1.0). More...
 
static double RandomFloatInRange (double minimum, double maximum)
 Convenience function that returns a doubvle precision floating point number within a given range. More...
 
static double BinaryMantissa (double value)
 Returns the binary mantissa of a given number, range 0.5 to 1.0. More...
 
static double BinaryExponent (double value)
 Returns the binary exponent of a given number. More...
 
- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 

Additional Inherited Members

- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

MMath is derived from MObject, and it only has static properties and methods.

No instances of the MMath class are possible.

Member Function Documentation

static MVariant MMath::Abs ( const MVariant num)
static

Returns the absolute value of the given parameter.

Internally the standard less-than comparison operator is used to compare the given number with zero. If the number is less than zero unary minus operator is applied.

Parameters
numNumeric value, positive or negative.
Returns
If num is negative -num is returned, otherwise num itself is returned.
static double MMath::Acos ( double  num)
inlinestatic

Returns the principal value of the arc cosine of num, expressed in radians.

In trigonometry, arc cosine is the inverse operation of cosine.

Parameters
numFloating point value in the interval [-1, +1].
Returns
Arc cosine of num, in the interval [0, pi] radians.
static double MMath::Asin ( double  num)
inlinestatic

Returns the principal value of the arc sine of num, expressed in radians.

In trigonometry, arc sine is the inverse operation of sine.

Parameters
numFloating point value in the interval [-1, +1].
Returns
Arc sine of num, in the interval [-pi/2, +pi/2] radians.
static double MMath::Atan ( double  num)
inlinestatic

Returns the principal value of the arc tangent of x, expressed in radians.

In trigonometry, arc tangent is the inverse operation of tangent.

Parameters
numFloating point value.
Returns
Principal arc tangent of num, in the interval [-pi/2, +pi/2] radians.
static double MMath::BinaryExponent ( double  value)
inlinestatic

Returns the binary exponent of a given number.

This is done by calling a C function frexp.

Parameters
valueSource number.
Returns
Binary exponent of the value.
static double MMath::BinaryMantissa ( double  value)
inlinestatic

Returns the binary mantissa of a given number, range 0.5 to 1.0.

This is done by calling a C function frexp.

Parameters
valueSource number.
Returns
Binary mantissa of the value, range 0.5 to 1.0.
static double MMath::Ceil ( double  num)
inlinestatic

Returns the closest from the right integer number to a given double precision floating point number.

In case the number is positive, the returned number will be no smaller than the one given. In case the number is negative, the returned number will be no bigger than the one given. If the number is NaN or any form of infinity, the same value is returned.

Parameters
numA number.
Returns
The result value is a double precision number, ceiling.
double x = MMath::Ceil(555.5); // x == 556.0
double y = MMath::Ceil(444.4); // y == 445.0
double z = MMath::Ceil(-2.6); // z == -2.0
See also
Floor - return the whole number closest from the left
static double MMath::Cos ( double  num)
inlinestatic

Returns the cosine of an angle of num radians.

Parameters
numFloating point value representing an angle expressed in radians.
Returns
Cosine of num.
static double MMath::Exp ( double  num)
static

Returns the base-e exponential function of num, which is e raised to the power num: e^num.

An error of type MEMath can be raised.

Parameters
numWhich number is the power of e.
Returns
result exponent value.
static double MMath::Floor ( double  num)
inlinestatic

Returns the closest from the left integer number to a given double precision floating point number.

In case the number is positive, the returned number will be no bigger than the one given. In case the number is negative, the returned number will be no smaller than the one given. If the number is NaN or any form of infinity, the same value is returned.

Parameters
numA number.
Returns
The result value is a double precision number, floor.

Usage:

double x = MMath::Floor(555.5); // x == 555.0
double y = MMath::Floor(444.1); // y == 444.0
double z = MMath::Floor(-2.6); // z == -3.0
See also
Ceil - return the whole number closest from the right
static double MMath::Log ( double  num)
static

Returns the natural logarithm of the number.

The natural logarithm is the base-e logarithm: the inverse of the natural exponential function (Exp).

An error of type MEMath wil be raised if the number is negative.

Parameters
numNumber.
Returns
result natural logarithm of the number.
static double MMath::Log10 ( double  num)
static

Returns the common (base-10) logarithm of num.

An error of type MEMath wil be raised if the number is negative.

Parameters
numNumber.
Returns
result decimal logarithm of the number.
static MVariant MMath::Max ( const MVariant v1,
const MVariant v2 
)
static

Returns the bigger of the two given parameters.

Internally the standard less-than comparison operator is used to compare the given values.

Parameters
v1One value, a number or a string, anything comparable using the order operator.
v2Another value, a number or a string, anything comparable using the order operator.
Returns
Either v1 or v2, whatever is bigger. If the values are equal then v1 is returned (same as v2, supposedly).
static MVariant MMath::Min ( const MVariant v1,
const MVariant v2 
)
static

Returns the smaller of the two two given parameters.

Internally the standard less-than comparison operator is used to compare the given values.

Parameters
v1One value, a number or a string, anything comparable using the order operator.
v2Another value, a number or a string, anything comparable using the order operator.
Returns
Either v1 or v2, whatever is smaller. If the values are equal then v2 is returned (same as v2, supposedly).
static double MMath::Pow ( double  x,
double  y 
)
static

Value of x raised into power y.

An error of type MEMath can be raised.

Parameters
xWhich number to raise.
yPower.
Returns
result value.
static double MMath::Pow10 ( int  power)
static

Facility function that efficiently returns the integer power of ten.

An error of type MEMath can be raised in case of overflow.

Parameters
powerInto which power 10 has to be raised.
Returns
result value.
static double MMath::Pow2 ( int  power)
static

Facility function that efficiently returns the integer power of two.

Negative numbers are respected. An error of type MEMath can be raised in case of overflow.

Parameters
powerInto which power 2 has to be raised.
Returns
result value.
static int MMath::Rand ( )
static

Pseudo-random integer number in range 0 .

. INT_MAX inclusively.

The name of the method (rand) has historic meaning as it is present in ANSI C standard library. Different from standard, this poarticular call always returns a value in the inclusive range [0 .. 0x7FFFFFFF].

The randomizer seed is guaranteed to be initialized before this call only if MeteringSDK threading is used. The returned value is not cryptograpically secure, but the algorithm is reasonably fast.

Returns
random number within inclusive range 0 .. INT_MAX.
See also
RandomInRange returns an unsigned value within a given range
RandomFloat returns a floating point value in range [0 .. 1.0)
RandomFloatInRange returns a floating point value within a given range
static double MMath::RandomFloat ( )
static

Returns a pseudo-random double precision floating point number in range [0.0 to 1.0).

Different from integer counterparts, RandomFloat is guaranteed to never return the value of its upper range, 1.0.

The randomizer seed is guaranteed to be initialized before this call only if MeteringSDK threading is used. The returned value is not cryptograpically secure, but the algorithm is reasonably fast.

Returns
random number within range [0.0 .. 1.0).
See also
Rand returns an integer value in range 0 .. INT_MAX.
RandomInRange returns an unsigned value within a given range.
RandomFloatInRange returns a floating point value within a given range.
static double MMath::RandomFloatInRange ( double  minimum,
double  maximum 
)
static

Convenience function that returns a doubvle precision floating point number within a given range.

The return value depends on function parameters in the following way:

  • If minimum is Infinity or NaN, minimum (NaN or Infinity) is returned.
  • If maximum is Infinity or NaN, maximum (NaN or Infinity) is returned.
  • There is a debug check to verify that the maximum value is not smaller than minimum. However, on release build, when the maximum is smaller than minimum, these two values will be swapped so they form a valid range.
  • If the maximum and the minimum are equal, the returned value will be the same as the minimum (and the maximum).
  • Otherwise, the return value will be a pseudo-random number within the given inclusive range. Linear distribution of probability is applied.

The randomizer seed is guaranteed to be initialized before this call only if MeteringSDK threading is used. The returned value is not cryptograpically secure, but the algorithm is reasonably fast.

Parameters
minimumMinimum value, inclusive.
maximumMaximum value, exclusive unless equal to minimum.
Returns
random Double precision floating point number within the given range.
See also
Rand returns an integer value within range 0 .. INT_MAX.
RandomInRange returns an unsigned value within a given range.
RandomFloat returns a floating point value in range [0 .. 1.0).
static unsigned MMath::RandomInRange ( unsigned  minimum,
unsigned  maximum 
)
static

Pseudo-random unsigned number within a given inclusive range.

The return value depends on function parameters in the following way:

  • There is a debug check to verify that the maximum value is not smaller than minimum. However, on release build, when the maximum is smaller than minimum, these two values will be swapped so they form a valid range.
  • If the maximum and the minimum are equal, the returned value will be the same as the minimum (and the maximum).
  • Otherwise, the return value will be a pseudo-random number within the given inclusive range. Linear distribution of probability is applied.

The randomizer seed is guaranteed to be initialized before this call only if MeteringSDK threading is used. The returned value is not cryptograpically secure, but the algorithm is reasonably fast.

Parameters
minimumMinimum value, inclusive
maximumMaximum value, inclusive, up to UINT_MAX.
Returns
random unsigned number within the given inclusive range
See also
Rand function with no parameters that returns a value in range 0 .. INT_MAX.
RandomFloat returns a floating point value in range [0 .. 1.0)
RandomFloatInRange returns a floating point value within a given range
static double MMath::Round ( double  val,
int  numDecimalPlaces = 0 
)
static

Round the floating point number to the given decimal digits after comma.

If the number is NaN or any form of infinity, the same value is returned.

Depending on the second parameter:

  • Rounding to zero digits after comma is equivalent to rounding to the nearest whole number.
  • Rounding to the positive number of digits is done to the nearest number of 1/10 for 1, 1/100 for 2, 1/1000 for 3, and so on.
  • Rounding to the negative number of digits is done to the nearest number of tens for 1, hundredths for 2, thousands for 3, and so on.

Rounding of halves is done upwards for positive numbers and downwards for negatives. In detail:

  • In case the number is positive, and it ends with x.5, the returned number will be the seiling of the one given so that 1.5 will be rounded up to 2.0, and so on.
  • In case the number is negative, and it ends with x.5, the returned number will be the floor of the one given so that -1.5 will be rounded down to -2.0, and so on.

The method attempts to perform the rounding precisely using the rules described above, however since IEEE-754 floating point numbers are binary, their approsimation to decimal cannot always be precise.

Parameters
valDouble precision floating point number to round.
numDecimalPlacesNumber of decimal places after comma, zero by default.
Returns
Result double precision floating point value approximated to the closest value with the given number of decimal points.

Usage:

double a = MMath::Round(0.555, 2); // 0.56
double b = MMath::Round(1.234567, 3); // 1.235
double c = MMath::Round(3456.78, -2); // 3500.0
double d = MMath::Round(-1.5, 0); // 2.0
static double MMath::Round0 ( double  val)
static

Round the floating point value to the nearest whole number.

If the number is NaN or any form of infinity, the same value is returned.

Rounding of halves is done upwards for positive numbers and downwards for negatives. In detail:

  • In case the number is positive, and it ends with x.5, the returned number will be the seiling of the one given so that 1.5 will be rounded up to 2.0, and so on.
  • In case the number is negative, and it ends with x.5, the returned number will be the floor of the one given so that -1.5 will be rounded down to -2.0, and so on.

The method attempts to perform the rounding precisely using the rules described above, however since IEEE-754 floating point numbers are binary, their approsimation to decimal cannot always be precise.

Parameters
valDouble precision floating point number to round.
Returns
Result double precision floating point value rounded to the closest whole number.

Usage:

double x = MMath::Round0(555.5); // 556.0
double y = MMath::Round0(444.4); // 444.0
double z = MMath::Round0(-77.5); // -78.0
static int MMath::RoundUpToPowerOfTwo ( int  x)
inlinestatic

Round a given integer number to the nearest power of two, which is bigger or equal to the initial number.

For negative numbers or zero, the value 1 is returned. Examples of other values: 2 -> 2, 3 -> 4, 4 -> 4, 9 -> 16, and so on.

Parameters
xThe number for which an upper power of two has to be found.
Returns
The result power of two number, bigger or equal to x.
See also
RoundUpToPowerOfTwo(unsigned x) - unsigned integer variant of this method.
static unsigned MMath::RoundUpToPowerOfTwo ( unsigned  x)
inlinestatic

Round a given unsigned integer number to the nearest power of two, which is bigger or equal to the initial number.

Examples of transformations made by this method: 2 -> 2, 3 -> 4, 4 -> 4, 9 -> 16, and so on.

Parameters
xThe number for which an upper power of two has to be found.
Returns
The result power of two number, bigger or equal to x.
See also
RoundUpToPowerOfTwo(int x) - signed integer variant of this method.
static double MMath::Sin ( double  num)
inlinestatic

Returns the sine of an angle of num radians.

Parameters
numFloating point value representing an angle expressed in radians.
Returns
Sine of num.
static double MMath::Sqrt ( double  arg)
static

Returns the square root of the given parameter.

If the argument is negative an error of type MEMath is raised.

Parameters
argValue to find square root from.
Returns
result value.
static double MMath::Tan ( double  num)
inlinestatic

Returns the tangent of an angle of num radians.

Parameters
numFloating point value representing an angle expressed in radians.
Returns
Tangent of num.