scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
|
Class that allows to handle percentages and do calculations with it easy. It supports normal percentages (with %), ppm, ppb, ppt and ppq. The types ppb, ppt and ppq are currently not supported because the float type in percentage class can't store so lower values. More...
#include <percentage.hpp>
Public Types | |
enum | type : int8_t { PERCENTAGE , RATIO , PARTS_PER_MILLION , PARTS_PER_BILLION , PARTS_PER_TRILLION , PARTS_PER_QUATRILLION } |
Type of percentage. More... | |
Public Member Functions | |
percentage () | |
Default constructor. The value is 0. | |
percentage (const percentage &x) | |
Copy constructor. The value is copied from the percentage x. | |
percentage (percentage &&x) | |
Move constructor. The value is moved from the percentage x. | |
percentage (float new_value, percentage::type init_type=percentage::PERCENTAGE) | |
Constructor. The value is new_value. Depending on the init_type given, the value is initialized as being a percentage or a ppm. | |
percentage (double new_value, percentage::type init_type=percentage::PERCENTAGE) | |
Constructor. The value is new_value (the double is casted to a float). Depending on the init_type given, the value is initialized as being a percentage or a ppm. | |
percentage (long double new_value, percentage::type init_type=percentage::PERCENTAGE) | |
Constructor. The value is new_value (the long double is casted to a float). Depending on the init_type given, the value is initialized as being a percentage or a ppm. | |
percentage (int new_value, percentage::type init_type=percentage::PERCENTAGE) | |
Constructor. The value is new_value (the int is casted to a float). Depending on the init_type given, the value is initialized as being a percentage or a ppm. | |
percentage (float new_value, const string &init_type) | |
Constructor. The value is new_value. init_type can be "%" or "ppm". Depending on the init_type given, the value is initialized as being a percentage or a ppm. | |
percentage (double new_value, const string &init_type) | |
Constructor. The value is new_value. init_type can be "%" or "ppm". Depending on the init_type given, the value is initialized as being a percentage or a ppm. | |
percentage (long double new_value, const string &init_type) | |
Constructor. The value is new_value. init_type can be "%" or "ppm". Depending on the init_type given, the value is initialized as being a percentage or a ppm. | |
percentage (int new_value, const string &init_type) | |
Constructor. The value is new_value. init_type can be "%" or "ppm". Depending on the init_type given, the value is initialized as being a percentage or a ppm. | |
percentage (const string &init_percentage) | |
Constructor. It initializes the value with an initialization string of percentage init_percentage. | |
percentage (const scalar_unit &x) | |
Constructor. The value is initialized to the same as the scalar_unit x, if it has empty dimensions. | |
percentage & | operator= (const percentage &x) |
Copy assignment. The value is copied from the percentage x. | |
percentage & | operator= (percentage &&x) |
Move assignment. The value is moved from the percentage x. | |
percentage & | operator= (float new_value) |
Assignment. The value is copied from new_value. | |
percentage & | operator= (double new_value) |
Assignment. The value is copied from new_value (the double is casted to a float). | |
percentage & | operator= (long double new_value) |
Assignment. The value is copied from new_value (the long double is casted to a float). | |
percentage & | operator= (int new_value) |
Assignment. The value is copied from new_value (the int is casted to a float). | |
percentage & | operator= (const string &init_percentage) |
Assignment. It initializes the value with an initialization string of percentage init_percentage. | |
percentage & | operator= (const scalar_unit &x) |
Assignment. The value is initialized to the same as the scalar_unit x, if it has empty dimensions. | |
operator float () const | |
The percentage is casted to a float. It returns the value. | |
const float & | get_value () const |
It returns the value. | |
percentage | operator+ (const percentage &x) const |
Creates a new percentage as the addition of two percentages. | |
percentage | operator- (const percentage &x) const |
Creates a new percentage as the difference of two percentages. | |
percentage | operator* (const percentage &x) const |
Creates a new percentage as the multiplication of two percentages. | |
percentage | operator/ (const percentage &x) const |
Creates a new percentage as the division of two percentages. | |
void | operator+= (const percentage &x) |
Sums the value with the value of the percentage x. | |
void | operator-= (const percentage &x) |
Substracts the value with the value of the percentage x. | |
void | operator*= (const percentage &x) |
Multiplies the value with the value of the percentage x. | |
void | operator/= (const percentage &x) |
Divides the value with the value of the percentage x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
void | operator= (T x) |
Assigns the value to be the numeric type x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
percentage | operator+ (T x) const |
Creates a new percentage as the addition of the percentage with the numeric type x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
percentage | operator- (T x) const |
Creates a new percentage as the difference of the percentage with the numeric type x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
float | operator* (T x) const |
Creates a new percentage as the multiplication of the percentage with the numeric type x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
float | operator/ (T x) const |
Creates a new percentage as the division of the percentage with the numeric type x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
void | operator+= (T x) |
Sums the value with the value of the numeric type x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
void | operator-= (T x) |
Substracts the value with the value of the numeric type x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
void | operator*= (T x) |
Multiplies the value with the value of the numeric type x. | |
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type> | |
void | operator/= (T x) |
Divides the value with the value of the numeric type x. | |
percentage & | operator++ () |
Increments the value by one. | |
percentage | operator++ (int) |
Increments the value by one. | |
percentage & | operator-- () |
Decrements the value by one. | |
percentage | operator-- (int) |
Decrements the value by one. | |
scalar_unit | operator* (const scalar_unit &x) const |
Multiplies the percentage with the scalar_unit x to create a percentage of that scalar_unit. | |
scalar_unit | operator/ (const scalar_unit &x) const |
Divides the percentage with the scalar_unit x to create a percentage of the inverse of that scalar_unit. | |
float | get_factor () const |
Returns the factor of the percentage, not his value. It equals is value divided by 100. | |
float | get_ppm () const |
Returns the factor of the percentage in ppm, not his value. It equals is value multiplied by 10,000. | |
string | display_percentage (int number_of_decimals=2) const |
Displays the percentage as normal percentage, with the % symbol. | |
string | display_ppm () const |
Displays the percentage as ppm, with the ppm symbol. | |
Private Member Functions | |
void | initialize_from_string (const string &init_percentage) |
Internal function. Initializes the member-variables with an initialization string of percentage. | |
Private Attributes | |
float | value |
The value of the percentage, in numbers related to a 100%. A percentage of 30% has a value of 30, not of 0.3 (the factor, instead, is 0.3f). When initializing the percentage from ppm, it's converted to the numeric equivalent of percentage. | |
Class that allows to handle percentages and do calculations with it easy. It supports normal percentages (with %), ppm, ppb, ppt and ppq. The types ppb, ppt and ppq are currently not supported because the float type in percentage class can't store so lower values.
Definition at line 16 of file percentage.hpp.
Type of percentage.
Definition at line 19 of file percentage.hpp.
percentage::percentage | ( | ) |
Default constructor. The value is 0.
Definition at line 16 of file percentage.cpp.
percentage::percentage | ( | const percentage & | x | ) |
Copy constructor. The value is copied from the percentage x.
Definition at line 19 of file percentage.cpp.
percentage::percentage | ( | percentage && | x | ) |
Move constructor. The value is moved from the percentage x.
Definition at line 22 of file percentage.cpp.
|
explicit |
Constructor. The value is new_value. Depending on the init_type given, the value is initialized as being a percentage or a ppm.
Definition at line 25 of file percentage.cpp.
|
explicit |
Constructor. The value is new_value (the double is casted to a float). Depending on the init_type given, the value is initialized as being a percentage or a ppm.
Definition at line 45 of file percentage.cpp.
|
explicit |
Constructor. The value is new_value (the long double is casted to a float). Depending on the init_type given, the value is initialized as being a percentage or a ppm.
Definition at line 65 of file percentage.cpp.
|
explicit |
Constructor. The value is new_value (the int is casted to a float). Depending on the init_type given, the value is initialized as being a percentage or a ppm.
Definition at line 85 of file percentage.cpp.
Constructor. The value is new_value. init_type can be "%" or "ppm". Depending on the init_type given, the value is initialized as being a percentage or a ppm.
Definition at line 101 of file percentage.cpp.
Constructor. The value is new_value. init_type can be "%" or "ppm". Depending on the init_type given, the value is initialized as being a percentage or a ppm.
Definition at line 129 of file percentage.cpp.
Constructor. The value is new_value. init_type can be "%" or "ppm". Depending on the init_type given, the value is initialized as being a percentage or a ppm.
Definition at line 157 of file percentage.cpp.
Constructor. The value is new_value. init_type can be "%" or "ppm". Depending on the init_type given, the value is initialized as being a percentage or a ppm.
Definition at line 185 of file percentage.cpp.
Constructor. It initializes the value with an initialization string of percentage init_percentage.
Definition at line 213 of file percentage.cpp.
|
explicit |
Constructor. The value is initialized to the same as the scalar_unit x, if it has empty dimensions.
Definition at line 218 of file percentage.cpp.
Displays the percentage as normal percentage, with the % symbol.
Definition at line 388 of file percentage.cpp.
string percentage::display_ppm | ( | ) | const |
Displays the percentage as ppm, with the ppm symbol.
Definition at line 395 of file percentage.cpp.
float percentage::get_factor | ( | ) | const |
Returns the factor of the percentage, not his value. It equals is value divided by 100.
Definition at line 363 of file percentage.cpp.
float percentage::get_ppm | ( | ) | const |
Returns the factor of the percentage in ppm, not his value. It equals is value multiplied by 10,000.
Definition at line 368 of file percentage.cpp.
Internal function. Initializes the member-variables with an initialization string of percentage.
Definition at line 423 of file percentage.cpp.
|
inlineexplicit |
The percentage is casted to a float. It returns the value.
Definition at line 44 of file percentage.hpp.
percentage percentage::operator* | ( | const percentage & | x | ) | const |
Creates a new percentage as the multiplication of two percentages.
Definition at line 297 of file percentage.cpp.
scalar_unit percentage::operator* | ( | const scalar_unit & | x | ) | const |
Multiplies the percentage with the scalar_unit x to create a percentage of that scalar_unit.
Definition at line 353 of file percentage.cpp.
Creates a new percentage as the multiplication of the percentage with the numeric type x.
Definition at line 82 of file percentage.hpp.
void percentage::operator*= | ( | const percentage & | x | ) |
Multiplies the value with the value of the percentage x.
Definition at line 317 of file percentage.cpp.
Multiplies the value with the value of the numeric type x.
Definition at line 106 of file percentage.hpp.
percentage percentage::operator+ | ( | const percentage & | x | ) | const |
Creates a new percentage as the addition of two percentages.
Definition at line 287 of file percentage.cpp.
|
inline |
Creates a new percentage as the addition of the percentage with the numeric type x.
Definition at line 70 of file percentage.hpp.
percentage & percentage::operator++ | ( | ) |
Increments the value by one.
Definition at line 327 of file percentage.cpp.
percentage percentage::operator++ | ( | int | ) |
Increments the value by one.
Definition at line 333 of file percentage.cpp.
void percentage::operator+= | ( | const percentage & | x | ) |
Sums the value with the value of the percentage x.
Definition at line 307 of file percentage.cpp.
Sums the value with the value of the numeric type x.
Definition at line 94 of file percentage.hpp.
percentage percentage::operator- | ( | const percentage & | x | ) | const |
Creates a new percentage as the difference of two percentages.
Definition at line 292 of file percentage.cpp.
|
inline |
Creates a new percentage as the difference of the percentage with the numeric type x.
Definition at line 76 of file percentage.hpp.
percentage & percentage::operator-- | ( | ) |
Decrements the value by one.
Definition at line 340 of file percentage.cpp.
percentage percentage::operator-- | ( | int | ) |
Decrements the value by one.
Definition at line 346 of file percentage.cpp.
void percentage::operator-= | ( | const percentage & | x | ) |
Substracts the value with the value of the percentage x.
Definition at line 312 of file percentage.cpp.
Substracts the value with the value of the numeric type x.
Definition at line 100 of file percentage.hpp.
percentage percentage::operator/ | ( | const percentage & | x | ) | const |
Creates a new percentage as the division of two percentages.
Definition at line 302 of file percentage.cpp.
scalar_unit percentage::operator/ | ( | const scalar_unit & | x | ) | const |
Divides the percentage with the scalar_unit x to create a percentage of the inverse of that scalar_unit.
Definition at line 358 of file percentage.cpp.
Creates a new percentage as the division of the percentage with the numeric type x.
Definition at line 88 of file percentage.hpp.
void percentage::operator/= | ( | const percentage & | x | ) |
Divides the value with the value of the percentage x.
Definition at line 322 of file percentage.cpp.
Divides the value with the value of the numeric type x.
Definition at line 112 of file percentage.hpp.
percentage & percentage::operator= | ( | const percentage & | x | ) |
Copy assignment. The value is copied from the percentage x.
Definition at line 231 of file percentage.cpp.
percentage & percentage::operator= | ( | const scalar_unit & | x | ) |
Assignment. The value is initialized to the same as the scalar_unit x, if it has empty dimensions.
Definition at line 273 of file percentage.cpp.
percentage & percentage::operator= | ( | const string & | init_percentage | ) |
Assignment. It initializes the value with an initialization string of percentage init_percentage.
Definition at line 267 of file percentage.cpp.
percentage & percentage::operator= | ( | double | new_value | ) |
Assignment. The value is copied from new_value (the double is casted to a float).
Definition at line 249 of file percentage.cpp.
percentage & percentage::operator= | ( | float | new_value | ) |
Assignment. The value is copied from new_value.
Definition at line 243 of file percentage.cpp.
percentage & percentage::operator= | ( | int | new_value | ) |
Assignment. The value is copied from new_value (the int is casted to a float).
Definition at line 261 of file percentage.cpp.
percentage & percentage::operator= | ( | long double | new_value | ) |
Assignment. The value is copied from new_value (the long double is casted to a float).
Definition at line 255 of file percentage.cpp.
percentage & percentage::operator= | ( | percentage && | x | ) |
Move assignment. The value is moved from the percentage x.
Definition at line 237 of file percentage.cpp.
Assigns the value to be the numeric type x.
Definition at line 64 of file percentage.hpp.
|
private |
The value of the percentage, in numbers related to a 100%. A percentage of 30% has a value of 30, not of 0.3 (the factor, instead, is 0.3f). When initializing the percentage from ppm, it's converted to the numeric equivalent of percentage.
Definition at line 139 of file percentage.hpp.