Skip to content

github-baron/FloatingMeasure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Synopsis

FloatingMeasure is a class API for physical calculations of floating point numbers with measures. For example the velocity is represented by an expression in your code like

CFloatingMeasure velocity = 150*km/h;

The measures can be any complex combination of simple measures and the mathematical operation "multiplication" and "division". In our example:

CComplexMeasure velocity_measure = km/h;  // consisting of </br>
CSimpleMeasure distance_measure = km; // combined with the time measure by the operator "/"
CSimpleMeasure time_measure = h;

A simple measure consists of a pre measure and a base measure . Thus, this API is easily extendable by any kind of pre measure or base measure.
In our example the distance_measure consists of the pre measure "k" (kilo) and the base measure "m" (meter).

The "floating" part of this API considers errors due to the numerical floating point representation. As a consequence e.g. the comparison operator allows equality for a range of values given by the numerical error instead of comparing to exact one value (which often fails .... unwanted).

Even the history (i.e. the sequence of mathematical operations) of these errors is considered and propagates depending on the mathematical operations and the operands and their error history.

Code Example

FMEx_Velocity.cpp :
An example for calculation of a velocity "v" of Usain Bolt, a snail, and the corresponding "snail factor".

FMEx_CheckMeasValue.cpp :
An example for checking a measurement value against a given tolerance: with and without considering a given precision.

Motivation

The FloatingMeasure API can be used in any metrological project. It helps avoiding those classical errors like "off by a factor of thousand" or any other potency of ten: the recalculation from one measure to another is made easy.

Additionally, it supports user given precision which is oftenly needed for "reasonable precise" numbers of a given metrological setup: see FMEx_CheckMeasValue.cpp for illustration.

Installation

The project can be compiled under Linux (CMake) and Windows (Visual Studio 2017). The corresponding build result can be found in the project directory build/CMake (for CMake) and build/VS (for Visual Studio). Distribute the corresponding "include" and "lib" directories to your favorite installation directory.

API Reference

Refere to the doxygen generated documentation here.

Tests

Testing is done via cppunit which can be found on github for usage under Windows (install and distribute with CMake). Under Linux (at least for Debian) it can be installed via apt.

For building with CMake the CMakeLists.txt file must be adapted for that. There must be a more elegant way ...

See how the testing is implemented FloatingMeasure_Test.cpp .

Contributors

Contributers are very welcome. Please, share your ideas of how want to use this API and adpat it to your needs.

Future Development

  • idea of "aliases" like : "1*V*A = 1*W" or "1*kg*m*m/s/s = 1*J"... just an idea
  • any extension of pre and base measures (see above example: "kg" is missing)
  • handling offsets (i.e. especially temperatures are not supported at the moment)
    • recalculation to SI-measures
    • simplification of complex measures

License

See my LICENSE (MIT).

About

FloatingMeasure is a c++ class API for physical calculations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published