libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
BaseLib::Math Class Reference

#include <Math.h>

Classes

class  Line
 Class defining a line. More...
 
class  Matrix3x3
 Class defining a 3x3 matrix. More...
 
class  Point2D
 Class defining a point in 2D space with numbers of type double. More...
 
class  Point3D
 
class  Triangle
 Class defining a triangle. More...
 

Public Types

typedef Point2D Vector2D
 
typedef Point3D Vector3D
 

Public Member Functions

 Math ()=delete
 
 ~Math ()=default
 Destructor. More...
 

Static Public Member Functions

static bool isNumber (const std::string &s, bool hex=false)
 Checks if a string is a number. More...
 
static int32_t getNumber (const std::string &s, bool isHex=false)
 Converts a string (decimal or hexadecimal) to an integer. More...
 
static int64_t getNumber64 (const std::string &s, bool isHex=false)
 Converts a string (decimal or hexadecimal) to an 64-bit integer. More...
 
static int32_t getOctalNumber (const std::string &s)
 Converts a octal string to an integer. More...
 
static int32_t getNumber (char hexChar)
 Converts a hexadecimal character to an integer. More...
 
static uint32_t getUnsignedNumber (const std::string &s, bool isHex=false)
 Converts a string (decimal or hexadecimal) to an unsigned integer. More...
 
static uint64_t getUnsignedNumber64 (const std::string &s, bool isHex=false)
 Converts a string (decimal or hexadecimal) to an unsigned integer. More...
 
static uint32_t getIeee754Binary32 (float value)
 
static uint64_t getIeee754Binary64 (double value)
 
static float getFloatFromIeee754Binary32 (uint32_t binary32)
 
static double getDoubleFromIeee754Binary64 (uint64_t binary64)
 
static double getDouble (const std::string &s)
 Converts a string to double. More...
 
static std::string toString (double number)
 Converts a double to string removing any trailing zeros. More...
 
static std::string toString (double number, int32_t precision)
 Converts a double to string. More...
 
static int32_t clamp (int32_t value, int32_t min, int32_t max)
 Forces a value between 'min' and 'max'. More...
 
static double clamp (double value, double min, double max)
 Forces a value between 'min' and 'max'. More...
 
static int32_t scale (int32_t value, int32_t valueMin, int32_t valueMax, int32_t scaleMin, int32_t scaleMax)
 Scales 'value' between 'valueMin' and 'valueMax' to 'scaleMin' and 'scaleMax'. More...
 
static double scale (double value, double valueMin, double valueMax, double scaleMin, double scaleMax)
 Scales 'value' between 'valueMin' and 'valueMax' to 'scaleMin' and 'scaleMax'. More...
 
static double Pow10 (int32_t exponent)
 Calculates powers to the base 10. More...
 
static double metricExponentialMovingAverage (double interval, double period, double metric, double lastAverage)
 Calculates the exponential moving average per time for performance metrics. More...
 

Static Protected Attributes

static const std::array< int32_t, 23 > _asciiToBinaryTable {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}
 Map to faster convert hexadecimal numbers. More...
 

Member Typedef Documentation

§ Vector2D

§ Vector3D

Constructor & Destructor Documentation

§ Math()

BaseLib::Math::Math ( )
delete

§ ~Math()

BaseLib::Math::~Math ( )
default

Destructor.

Does nothing.

Member Function Documentation

§ clamp() [1/2]

int32_t BaseLib::Math::clamp ( int32_t  value,
int32_t  min,
int32_t  max 
)
static

Forces a value between 'min' and 'max'.

If the value is larger than 'max' then it is set to 'max'. If the value is smaller than 'man' it is set to 'min'.

Parameters
valueThe number to clamp.
minThe lower boundary.
maxThe upper boundary.
Returns
Returns the clamped number.

§ clamp() [2/2]

double BaseLib::Math::clamp ( double  value,
double  min,
double  max 
)
static

Forces a value between 'min' and 'max'.

If the value is larger than 'max' then it is set to 'max'. If the value is smaller than 'man' it is set to 'min'.

Parameters
valueThe number to clamp.
minThe lower boundary.
maxThe upper boundary.
Returns
Returns the clamped number.

§ getDouble()

double BaseLib::Math::getDouble ( const std::string &  s)
static

Converts a string to double.

See also
getNumber()
getUnsignedNumber()
Parameters
sThe string to convert to double.
Returns
Returns the number or "0" if the conversion was not successful.

§ getDoubleFromIeee754Binary64()

double BaseLib::Math::getDoubleFromIeee754Binary64 ( uint64_t  binary64)
static

§ getFloatFromIeee754Binary32()

float BaseLib::Math::getFloatFromIeee754Binary32 ( uint32_t  binary32)
static

§ getIeee754Binary32()

uint32_t BaseLib::Math::getIeee754Binary32 ( float  value)
static

§ getIeee754Binary64()

uint64_t BaseLib::Math::getIeee754Binary64 ( double  value)
static

§ getNumber() [1/2]

int32_t BaseLib::Math::getNumber ( const std::string &  s,
bool  isHex = false 
)
static

Converts a string (decimal or hexadecimal) to an integer.

See also
getDouble()
getUnsignedNumber()
getUnsignedNumber64()
getNumber()
getNumber64()
getOctalNumber()
Parameters
sThe string to convert.
isHexSet this parameter to "true", if the string is hexadecimal (default false). If the string is prefixed with "0x", it is automatically detected as hexadecimal.
Returns
Returns the integer or "0" on error.

§ getNumber() [2/2]

int32_t BaseLib::Math::getNumber ( char  hexChar)
static

Converts a hexadecimal character to an integer.

See also
getDouble()
getUnsignedNumber()
getUnsignedNumber64()
getNumber64()
getOctalNumber()
Parameters
hexCharThe hexadecimal character.
Returns
Returns the integer or "0" on error.

§ getNumber64()

int64_t BaseLib::Math::getNumber64 ( const std::string &  s,
bool  isHex = false 
)
static

Converts a string (decimal or hexadecimal) to an 64-bit integer.

See also
getDouble()
getUnsignedNumber()
getUnsignedNumber64()
getNumber64()
getOctalNumber()
Parameters
sThe string to convert.
isHexSet this parameter to "true", if the string is hexadecimal (default false). If the string is prefixed with "0x", it is automatically detected as hexadecimal.
Returns
Returns the integer or "0" on error.

§ getOctalNumber()

int32_t BaseLib::Math::getOctalNumber ( const std::string &  s)
static

Converts a octal string to an integer.

See also
getDouble()
getUnsignedNumber()
getUnsignedNumber64()
getNumber()
getNumber64()
Parameters
sThe string to convert.
Returns
Returns the integer or "0" on error.

§ getUnsignedNumber()

uint32_t BaseLib::Math::getUnsignedNumber ( const std::string &  s,
bool  isHex = false 
)
static

Converts a string (decimal or hexadecimal) to an unsigned integer.

See also
getDouble()
getNumber()
getNumber64()
getUnsignedNumber64()
getOctalNumber()
Parameters
sThe string to convert.
isHexSet this parameter to "true", if the string is hexadecimal (default false). If the string is prefixed with "0x", it is automatically detected as hexadecimal.
Returns
Returns the unsigned integer or "0" on error.

§ getUnsignedNumber64()

uint64_t BaseLib::Math::getUnsignedNumber64 ( const std::string &  s,
bool  isHex = false 
)
static

Converts a string (decimal or hexadecimal) to an unsigned integer.

See also
getDouble()
getNumber()
getNumber64()
getUnsignedNumber()
getOctalNumber()
Parameters
sThe string to convert.
isHexSet this parameter to "true", if the string is hexadecimal (default false). If the string is prefixed with "0x", it is automatically detected as hexadecimal.
Returns
Returns the unsigned integer or "0" on error.

§ isNumber()

bool BaseLib::Math::isNumber ( const std::string &  s,
bool  hex = false 
)
static

Checks if a string is a number.

Parameters
sThe string to check.
hex(default false) Set to "true" if s contains a hexadecimal number.
Returns
Returns true if the string is a decimal or hexadecimal number, otherwise false.

§ metricExponentialMovingAverage()

double BaseLib::Math::metricExponentialMovingAverage ( double  interval,
double  period,
double  metric,
double  lastAverage 
)
static

Calculates the exponential moving average per time for performance metrics.

Parameters
intervalThe time since the last measurements. The time unit doesn't matter as long as it is the same unit as for period.
periodThe time to average over (e. g. 60 seconds or 15 minutes). The time unit doesn't matter as long as it is the same as for interval.
metricThe current performance measurement.
lastAverageThe last output of this method. Pass 0 when this is the first call.
Returns
Returns the average over the given time period.

§ Pow10()

static double BaseLib::Math::Pow10 ( int32_t  exponent)
inlinestatic

Calculates powers to the base 10.

§ scale() [1/2]

int32_t BaseLib::Math::scale ( int32_t  value,
int32_t  valueMin,
int32_t  valueMax,
int32_t  scaleMin,
int32_t  scaleMax 
)
static

Scales 'value' between 'valueMin' and 'valueMax' to 'scaleMin' and 'scaleMax'.

Parameters
valueThe value to scale.
valueMinThe lowest possible value of 'value'.
valueMaxThe highest possible value of 'value'.
scaleMinThe lowest value to scale 'value' to.
scaleMaxThe highest value to scale 'value' to.
Returns
Returns the number.

§ scale() [2/2]

double BaseLib::Math::scale ( double  value,
double  valueMin,
double  valueMax,
double  scaleMin,
double  scaleMax 
)
static

Scales 'value' between 'valueMin' and 'valueMax' to 'scaleMin' and 'scaleMax'.

Parameters
valueThe value to scale.
valueMinThe lowest possible value of 'value'.
valueMaxThe highest possible value of 'value'.
scaleMinThe lowest value to scale 'value' to.
scaleMaxThe highest value to scale 'value' to.
Returns
Returns the number.

§ toString() [1/2]

std::string BaseLib::Math::toString ( double  number)
static

Converts a double to string removing any trailing zeros.

Parameters
numberThe number to convert
Returns
Returns the number.

§ toString() [2/2]

std::string BaseLib::Math::toString ( double  number,
int32_t  precision 
)
static

Converts a double to string.

Parameters
numberThe number to convert
precisionThe precision
Returns
Returns the number.

Member Data Documentation

§ _asciiToBinaryTable

const std::array< int32_t, 23 > BaseLib::Math::_asciiToBinaryTable {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}
staticprotected

Map to faster convert hexadecimal numbers.


The documentation for this class was generated from the following files: