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
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
scifir::percentage Class Reference

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.
 
percentageoperator= (const percentage &x)
 Copy assignment. The value is copied from the percentage x.
 
percentageoperator= (percentage &&x)
 Move assignment. The value is moved from the percentage x.
 
percentageoperator= (float new_value)
 Assignment. The value is copied from new_value.
 
percentageoperator= (double new_value)
 Assignment. The value is copied from new_value (the double is casted to a float).
 
percentageoperator= (long double new_value)
 Assignment. The value is copied from new_value (the long double is casted to a float).
 
percentageoperator= (int new_value)
 Assignment. The value is copied from new_value (the int is casted to a float).
 
percentageoperator= (const string &init_percentage)
 Assignment. It initializes the value with an initialization string of percentage init_percentage.
 
percentageoperator= (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 floatget_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.
 
percentageoperator++ ()
 Increments the value by one.
 
percentage operator++ (int)
 Increments the value by one.
 
percentageoperator-- ()
 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.
 

Detailed Description

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.

Member Enumeration Documentation

◆ type

Type of percentage.

Enumerator
PERCENTAGE 

Normal percentage, with the % symbol.

RATIO 

The normal percentage obtained by a direct ratio of some proportion, you don't need to multiply by 100.

PARTS_PER_MILLION 

Percentage, with the ppm symbol. Commonly used in chemistry, it represents 1 in 10^6.

PARTS_PER_BILLION 

Percentage, with the ppb symbol. Commonly used in chemistry, it represents 1 in 10^9.

PARTS_PER_TRILLION 

Percentage, with the ppt symbol. Commonly used in chemistry, it represents 1 in 10^12.

PARTS_PER_QUATRILLION 

Percentage, with the ppq symbol. Commonly used in chemistry, it represents 1 in 10^15.

Definition at line 19 of file percentage.hpp.

@ PARTS_PER_MILLION
Percentage, with the ppm symbol. Commonly used in chemistry, it represents 1 in 10^6.
@ RATIO
The normal percentage obtained by a direct ratio of some proportion, you don't need to multiply by 10...
@ PARTS_PER_TRILLION
Percentage, with the ppt symbol. Commonly used in chemistry, it represents 1 in 10^12.
@ PERCENTAGE
Normal percentage, with the % symbol.
@ PARTS_PER_QUATRILLION
Percentage, with the ppq symbol. Commonly used in chemistry, it represents 1 in 10^15.
@ PARTS_PER_BILLION
Percentage, with the ppb symbol. Commonly used in chemistry, it represents 1 in 10^9.

Constructor & Destructor Documentation

◆ percentage() [1/13]

percentage::percentage ( )

Default constructor. The value is 0.

Definition at line 16 of file percentage.cpp.

16 : value(0.0f)
17 {}
float value
The value of the percentage, in numbers related to a 100%. A percentage of 30% has a value of 30,...

◆ percentage() [2/13]

percentage::percentage ( const percentage x)

Copy constructor. The value is copied from the percentage x.

Definition at line 19 of file percentage.cpp.

19 : value(x.get_value())
20 {}

◆ percentage() [3/13]

percentage::percentage ( percentage &&  x)

Move constructor. The value is moved from the percentage x.

Definition at line 22 of file percentage.cpp.

22 : value(std::move(x.get_value()))
23 {}

◆ percentage() [4/13]

percentage::percentage ( float  new_value,
percentage::type  init_type = percentage::PERCENTAGE 
)
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.

25 : value()
26 {
27 if (init_type == percentage::PERCENTAGE)
28 {
29 value = new_value;
30 }
31 else if (init_type == percentage::RATIO)
32 {
33 value = new_value * 100.0f;
34 }
35 else if (init_type == percentage::PARTS_PER_MILLION)
36 {
37 value = new_value / 10000.0f;
38 }
39 else
40 {
41 value = 0.0f;
42 }
43 }

◆ percentage() [5/13]

percentage::percentage ( double  new_value,
percentage::type  init_type = percentage::PERCENTAGE 
)
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.

45 : value()
46 {
47 if (init_type == percentage::PERCENTAGE)
48 {
49 value = float(new_value);
50 }
51 else if (init_type == percentage::RATIO)
52 {
53 value = float(new_value) * 100.0f;
54 }
55 else if (init_type == percentage::PARTS_PER_MILLION)
56 {
57 value = float(new_value) / 10000.0f;
58 }
59 else
60 {
61 value = 0.0f;
62 }
63 }

◆ percentage() [6/13]

percentage::percentage ( long double  new_value,
percentage::type  init_type = percentage::PERCENTAGE 
)
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.

65 : value()
66 {
67 if (init_type == percentage::PERCENTAGE)
68 {
69 value = float(new_value);
70 }
71 else if (init_type == percentage::RATIO)
72 {
73 value = float(new_value) * 100.0f;
74 }
75 else if (init_type == percentage::PARTS_PER_MILLION)
76 {
77 value = float(new_value) / 10000.0f;
78 }
79 else
80 {
81 value = 0.0f;
82 }
83 }

◆ percentage() [7/13]

percentage::percentage ( int  new_value,
percentage::type  init_type = percentage::PERCENTAGE 
)
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.

85 : value()
86 {
87 if (init_type == percentage::PERCENTAGE)
88 {
89 value = float(new_value);
90 }
91 else if (init_type == percentage::PARTS_PER_MILLION)
92 {
93 value = float(new_value) / 10000.0f;
94 }
95 else
96 {
97 value = 0.0f;
98 }
99 }

◆ percentage() [8/13]

percentage::percentage ( float  new_value,
const string init_type 
)
explicit

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.

102 {
103 if (init_type == "%")
104 {
105 value = new_value;
106 }
107 else if (init_type == "ppm")
108 {
109 value = new_value / 10000.0f;
110 }
111 else
112 {
113 value = 0.0f;
114 }
115 /*else if (init_type == "ppb")
116 {
117 value = new_value / 10000000.0f;
118 }
119 else if (init_type == "ppt")
120 {
121 value = new_value / 10000000000.0f;
122 }
123 else if (init_type == "ppq")
124 {
125 value = new_value / 10000000000000.0f;
126 }*/
127 }

◆ percentage() [9/13]

percentage::percentage ( double  new_value,
const string init_type 
)
explicit

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.

130 {
131 if (init_type == "%")
132 {
133 value = float(new_value);
134 }
135 else if (init_type == "ppm")
136 {
137 value = float(new_value) / 10000.0f;
138 }
139 else
140 {
141 value = 0.0f;
142 }
143 /*else if (init_type == "ppb")
144 {
145 value = float(new_value) / 10000000.0f;
146 }
147 else if (init_type == "ppt")
148 {
149 value = float(new_value) / 10000000000.0f;
150 }
151 else if (init_type == "ppq")
152 {
153 value = float(new_value) / 10000000000000.0f;
154 }*/
155 }

◆ percentage() [10/13]

percentage::percentage ( long double  new_value,
const string init_type 
)
explicit

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.

158 {
159 if (init_type == "%")
160 {
161 value = float(new_value);
162 }
163 else if (init_type == "ppm")
164 {
165 value = float(new_value) / 10000.0f;
166 }
167 else
168 {
169 value = 0.0f;
170 }
171 /*else if (init_type == "ppb")
172 {
173 value = float(new_value) / 10000000.0f;
174 }
175 else if (init_type == "ppt")
176 {
177 value = float(new_value) / 10000000000.0f;
178 }
179 else if (init_type == "ppq")
180 {
181 value = float(new_value) / 10000000000000.0f;
182 }*/
183 }

◆ percentage() [11/13]

percentage::percentage ( int  new_value,
const string init_type 
)
explicit

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.

186 {
187 if (init_type == "%")
188 {
189 value = float(new_value);
190 }
191 else if (init_type == "ppm")
192 {
193 value = float(new_value) / 10000.0f;
194 }
195 else
196 {
197 value = 0.0f;
198 }
199 /*else if (init_type == "ppb")
200 {
201 value = float(new_value) / 10000000.0f;
202 }
203 else if (init_type == "ppt")
204 {
205 value = float(new_value) / 10000000000.0f;
206 }
207 else if (init_type == "ppq")
208 {
209 value = float(new_value) / 10000000000000.0f;
210 }*/
211 }

◆ percentage() [12/13]

percentage::percentage ( const string init_percentage)
explicit

Constructor. It initializes the value with an initialization string of percentage init_percentage.

Definition at line 213 of file percentage.cpp.

213 : value()
214 {
215 initialize_from_string(init_percentage);
216 }
void initialize_from_string(const string &init_percentage)
Internal function. Initializes the member-variables with an initialization string of percentage.

◆ percentage() [13/13]

percentage::percentage ( const scalar_unit x)
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.

219 {
220 if (x.has_empty_dimensions())
221 {
222 value = float(x);
223 }
224 else
225 {
226 cerr << "A percentage cannot be initialized with dimensions" << endl;
227 value = 0.0f;
228 }
229 }

Member Function Documentation

◆ display_percentage()

string percentage::display_percentage ( int  number_of_decimals = 2) const

Displays the percentage as normal percentage, with the % symbol.

Definition at line 388 of file percentage.cpp.

389 {
390 ostringstream out;
391 out << display_float(value,number_of_decimals) << "%";
392 return out.str();
393 }
string display_float(const float &value, int number_of_decimals)
Definition types.cpp:36

◆ display_ppm()

string percentage::display_ppm ( ) const

Displays the percentage as ppm, with the ppm symbol.

Definition at line 395 of file percentage.cpp.

396 {
397 ostringstream out;
398 out << display_float(get_ppm()) << " ppm";
399 return out.str();
400 }
float get_ppm() const
Returns the factor of the percentage in ppm, not his value. It equals is value multiplied by 10,...

◆ get_factor()

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.

364 {
365 return value / 100.0f;
366 }

◆ get_ppm()

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.

369 {
370 return value * 10000.0f;
371 }

◆ get_value()

const float & percentage::get_value ( ) const
inline

It returns the value.

Definition at line 49 of file percentage.hpp.

50 {
51 return value;
52 }

◆ initialize_from_string()

void percentage::initialize_from_string ( const string init_percentage)
private

Internal function. Initializes the member-variables with an initialization string of percentage.

Definition at line 423 of file percentage.cpp.

424 {
425 if (init_percentage[init_percentage.length() - 1] == '%')
426 {
427 value = stof(init_percentage.substr(0,init_percentage.length() - 1));
428 }
429 else if (init_percentage.find(" ") != string::npos)
430 {
431 string percentage_unit = init_percentage.substr(init_percentage.length() - 4,4);
432 if (percentage_unit == " ppm")
433 {
434 value = stof(init_percentage.substr(0,init_percentage.length() - 4)) / 10000.0f;
435 }
436 else
437 {
438 value = 0.0f;
439 }
440 /*else if (percentage_unit == " ppb")
441 {
442 value = stof(init_percentage.substr(0,init_percentage.length() - 4)) / 10000000.0f;
443 }
444 else if (percentage_unit == " ppt")
445 {
446 value = stof(init_percentage.substr(0,init_percentage.length() - 4)) / 10000000000.0f;
447 }
448 else if (percentage_unit == " ppq")
449 {
450 value = stof(init_percentage.substr(0,init_percentage.length() - 4)) / 10000000000000.0f;
451 }*/
452 }
453 else if (init_percentage.length() > 3)
454 {
455 string percentage_unit = init_percentage.substr(init_percentage.length() - 3,3);
456 if (percentage_unit == "ppm")
457 {
458 value = stof(init_percentage.substr(0,init_percentage.length() - 3)) / 10000.0f;
459 }
460 /*else if (percentage_unit == "ppb")
461 {
462 value = stof(init_percentage.substr(0,init_percentage.length() - 3)) / 10000000.0f;
463 }
464 else if (percentage_unit == "ppt")
465 {
466 value = stof(init_percentage.substr(0,init_percentage.length() - 3)) / 10000000000.0f;
467 }
468 else if (percentage_unit == "ppq")
469 {
470 value = stof(init_percentage.substr(0,init_percentage.length() - 3)) / 10000000000000.0f;
471 }*/
472 else
473 {
474 value = 0.0f;
475 }
476 }
477 else
478 {
479 value = 0.0f;
480 }
481 }

◆ operator float()

percentage::operator float ( ) const
inlineexplicit

The percentage is casted to a float. It returns the value.

Definition at line 44 of file percentage.hpp.

45 {
46 return float(value);
47 }

◆ operator*() [1/3]

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.

298 {
299 return percentage(value * x.get_value() / 100.0f);
300 }
percentage()
Default constructor. The value is 0.

◆ operator*() [2/3]

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.

354 {
355 return get_factor() * x;
356 }
float get_factor() const
Returns the factor of the percentage, not his value. It equals is value divided by 100.

◆ operator*() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
float percentage::operator* ( T  x) const
inline

Creates a new percentage as the multiplication of the percentage with the numeric type x.

Definition at line 82 of file percentage.hpp.

83 {
84 return float(value * x / 100);
85 }

◆ operator*=() [1/2]

void percentage::operator*= ( const percentage x)

Multiplies the value with the value of the percentage x.

Definition at line 317 of file percentage.cpp.

318 {
319 value *= (x.get_value() / 100.0f);
320 }

◆ operator*=() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void percentage::operator*= ( T  x)
inline

Multiplies the value with the value of the numeric type x.

Definition at line 106 of file percentage.hpp.

107 {
108 value *= x;
109 }

◆ operator+() [1/2]

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.

288 {
289 return percentage(value + x.get_value());
290 }

◆ operator+() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
percentage percentage::operator+ ( T  x) const
inline

Creates a new percentage as the addition of the percentage with the numeric type x.

Definition at line 70 of file percentage.hpp.

71 {
72 return percentage(value + x);
73 }

◆ operator++() [1/2]

percentage & percentage::operator++ ( )

Increments the value by one.

Definition at line 327 of file percentage.cpp.

328 {
329 value++;
330 return *this;
331 }

◆ operator++() [2/2]

percentage percentage::operator++ ( int  )

Increments the value by one.

Definition at line 333 of file percentage.cpp.

334 {
335 percentage tmp = percentage(*this);
336 operator ++();
337 return tmp;
338 }
percentage & operator++()
Increments the value by one.

◆ operator+=() [1/2]

void percentage::operator+= ( const percentage x)

Sums the value with the value of the percentage x.

Definition at line 307 of file percentage.cpp.

308 {
309 value += x.get_value();
310 }

◆ operator+=() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void percentage::operator+= ( T  x)
inline

Sums the value with the value of the numeric type x.

Definition at line 94 of file percentage.hpp.

95 {
96 value += x;
97 }

◆ operator-() [1/2]

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.

293 {
294 return percentage(value - x.get_value());
295 }

◆ operator-() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
percentage percentage::operator- ( T  x) const
inline

Creates a new percentage as the difference of the percentage with the numeric type x.

Definition at line 76 of file percentage.hpp.

77 {
78 return percentage(value - x);
79 }

◆ operator--() [1/2]

percentage & percentage::operator-- ( )

Decrements the value by one.

Definition at line 340 of file percentage.cpp.

341 {
342 value--;
343 return *this;
344 }

◆ operator--() [2/2]

percentage percentage::operator-- ( int  )

Decrements the value by one.

Definition at line 346 of file percentage.cpp.

347 {
348 percentage tmp = percentage(*this);
349 operator --();
350 return tmp;
351 }
percentage & operator--()
Decrements the value by one.

◆ operator-=() [1/2]

void percentage::operator-= ( const percentage x)

Substracts the value with the value of the percentage x.

Definition at line 312 of file percentage.cpp.

313 {
314 value -= x.get_value();
315 }

◆ operator-=() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void percentage::operator-= ( T  x)
inline

Substracts the value with the value of the numeric type x.

Definition at line 100 of file percentage.hpp.

101 {
102 value -= x;
103 }

◆ operator/() [1/3]

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.

303 {
304 return percentage(100.0f * value / x.get_value());
305 }

◆ operator/() [2/3]

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.

359 {
360 return get_factor() / x;
361 }

◆ operator/() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
float percentage::operator/ ( T  x) const
inline

Creates a new percentage as the division of the percentage with the numeric type x.

Definition at line 88 of file percentage.hpp.

89 {
90 return float(value / (100 * x));
91 }

◆ operator/=() [1/2]

void percentage::operator/= ( const percentage x)

Divides the value with the value of the percentage x.

Definition at line 322 of file percentage.cpp.

323 {
324 value *= 100.0f / x.get_value();
325 }

◆ operator/=() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void percentage::operator/= ( T  x)
inline

Divides the value with the value of the numeric type x.

Definition at line 112 of file percentage.hpp.

113 {
114 value /= x;
115 }

◆ operator=() [1/9]

percentage & percentage::operator= ( const percentage x)

Copy assignment. The value is copied from the percentage x.

Definition at line 231 of file percentage.cpp.

232 {
233 value = x.get_value();
234 return *this;
235 }

◆ operator=() [2/9]

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.

274 {
275 if (x.has_empty_dimensions())
276 {
277 value = x.get_value();
278 }
279 else
280 {
281 cerr << "A percentage cannot be initialized with dimensions" << endl;
282 value = 0.0f;
283 }
284 return *this;
285 }

◆ operator=() [3/9]

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.

268 {
269 initialize_from_string(init_percentage);
270 return *this;
271 }

◆ operator=() [4/9]

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.

250 {
251 value = float(new_value);
252 return *this;
253 }

◆ operator=() [5/9]

percentage & percentage::operator= ( float  new_value)

Assignment. The value is copied from new_value.

Definition at line 243 of file percentage.cpp.

244 {
245 value = new_value;
246 return *this;
247 }

◆ operator=() [6/9]

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.

262 {
263 value = float(new_value);
264 return *this;
265 }

◆ operator=() [7/9]

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.

256 {
257 value = float(new_value);
258 return *this;
259 }

◆ operator=() [8/9]

percentage & percentage::operator= ( percentage &&  x)

Move assignment. The value is moved from the percentage x.

Definition at line 237 of file percentage.cpp.

238 {
239 value = std::move(x.get_value());
240 return *this;
241 }

◆ operator=() [9/9]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void percentage::operator= ( T  x)
inline

Assigns the value to be the numeric type x.

Definition at line 64 of file percentage.hpp.

65 {
66 value = x;
67 }

Member Data Documentation

◆ value

float percentage::value
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.


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