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 Member Functions | Protected Member Functions | Protected Attributes | List of all members
scifir::scalar_unit Class Reference

Class that allows to create scalar units, which are composed of a value (as a float) and dimensions. The dimensions can be of any number, and be simple dimensions, composite dimensions and/or special names of dimensions. All base and derived scalar unit classes inherit from scalar_unit. Initialization string example: "1 N". More...

#include <scalar_unit.hpp>

Inheritance diagram for scifir::scalar_unit:
Inheritance graph
[legend]

Public Member Functions

 scalar_unit ()
 Default constructor, the value is 0 and the dimensions are empty.
 
 scalar_unit (const scalar_unit &x)
 Copy constructor, copies the value and the dimensions.
 
 scalar_unit (scalar_unit &&x)
 Move constructor, moves the value and the dimensions.
 
 scalar_unit (float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 scalar_unit (double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 scalar_unit (long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 scalar_unit (int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position=dimension::NUMERATOR)
 
 scalar_unit (float new_value, const string &init_dimensions)
 Creates a new scalar_unit with the value and with the dimensions specified in the string.
 
 scalar_unit (double new_value, const string &init_dimensions)
 Creates a new scalar_unit, the double is casted to a float.
 
 scalar_unit (long double new_value, const string &init_dimensions)
 Creates a new scalar_unit, the long double is casted to a float.
 
 scalar_unit (int new_value, const string &init_dimensions)
 Creates a new scalar_unit, the int is casted to a float.
 
 scalar_unit (float new_value, const vector< dimension > &new_dimensions)
 Creates a new scalar_unit with the value given and copying the dimensions.
 
 scalar_unit (double new_value, const vector< dimension > &new_dimensions)
 Creates a new scalar_unit, the double is casted to a float, the dimensions are copied.
 
 scalar_unit (long double new_value, const vector< dimension > &new_dimensions)
 Creates a new scalar_unit, the long double is casted to a float, the dimensions are copied.
 
 scalar_unit (int new_value, const vector< dimension > &new_dimensions)
 Creates a new scalar_unit, the int is casted to a float, the dimensions are copied.
 
 scalar_unit (const string &init_scalar)
 Creates a new scalar_unit, the initialization string specifies both the value and the dimensions.
 
scalar_unitoperator= (const scalar_unit &x)
 Copy assignment, it assigns a copy of the scalar_unit.
 
scalar_unitoperator= (scalar_unit &&x)
 Move assignment, it moves the scalar_unit.
 
scalar_unitoperator= (const string &init_scalar)
 Assignment with an initialization string, the value and the dimensions are both specified.
 
 operator float () const
 Cast the scalar_unit to their float equivalent, it discards the dimensions and copies the value to a float.
 
bool operator== (scalar_unit x) const
 Comparison operator, two scalar_unit classes are considered equivalent if they have the same value given the same dimensions.
 
scalar_unit operator+ (scalar_unit x) const
 Addition operator, it sums two scalar_unit classes, their dimensions are changed to be equal first. If the basic dimensions are different, it returns an empty scalar_unit class.
 
scalar_unit operator- (scalar_unit x) const
 Substraction operator, it substracts one scalar_unit from the other, their dimensions are changed to be equal first. If the basic dimensions are different, it returns an empty scalar_unit class.
 
scalar_unit operator* (scalar_unit x) const
 Multiplication operator, it multiplies two scalar_unit classes, their dimensions are also multiplied.
 
scalar_unit operator/ (scalar_unit x) const
 Division operator, it divides one scalar_unit class with the other, their dimensions are also divided.
 
scalar_unit operator^ (const scalar_unit &x) const
 Power operator, it powers a scalar_unit class with another, if that second scalar_unit class, which is the exponent, as empty dimensions. If the exponent doesn't has empty dimensions it returns an empty scalar_unit class.
 
void operator+= (scalar_unit x)
 Addition operator, it adds a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't sums to the value.
 
void operator-= (scalar_unit x)
 Substraction operator, it substracts a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't substracts to the value.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit operator+ (T y) const
 Addition operator, it sums the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit operator- (T y) const
 Substraction operator, it substracts the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit operator* (T y) const
 Multiplication operator, it multiplies the numeric type with the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit operator/ (T y) const
 Division operator, it divides the value with the numeric type, independent of the dimensions.
 
template<typename T , typename = typename enable_if<is_integer_number<T>::value>::type>
scalar_unit operator^ (T y) const
 Power operator, it powers the value with the numeric type, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator+= (T y)
 Addition operator, it adds the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator-= (T y)
 Substraction operator, it substracts the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator*= (T y)
 Multiplication operator, it multiplies the numeric type to the value, independent of the dimensions.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
void operator/= (T y)
 Division operator, it divides the numeric type to the value, independent of the dimensions.
 
scalar_unitoperator++ ()
 Increment operator, it increases the value by one.
 
scalar_unitoperator++ (int)
 Increment operator, it increases the value by one.
 
scalar_unitoperator-- ()
 Decrement operator, it decreases the value by one.
 
scalar_unitoperator-- (int)
 Decrement operator, it decreases the value by one.
 
void change_dimensions (const string &init_dimensions)
 Changes the dimensions to the dimensions specified by the initialization string of dimensions.
 
void change_dimensions (const scalar_unit &x)
 Changes the dimensions to the same dimensions of the scalar_unit.
 
bool has_dimensions (const string &init_dimensions) const
 Checks if the basic dimensions are the same as the initialization string of dimensions.
 
bool has_dimensions (const vector< dimension > &x_dimensions) const
 Checks if the basic dimensions are the same as some set of dimensions.
 
bool has_dimensions (const scalar_unit &x) const
 Checks if the basic dimensions are the same as other scalar_unit.
 
bool has_empty_dimensions () const
 Checks if there aren't base dimensions.
 
bool is_dimensionless () const
 Returns true if there aren't dimensions or if all dimensions are dimensionless.
 
bool has_simple_dimensions () const
 Returns true if there's only a simple dimension.
 
bool has_single_dimensions () const
 Returns true if there's only one dimension, which can be simple or composite.
 
bool has_composite_dimensions () const
 Returns true is there's more than one simple dimension.
 
string display_dimensions () const
 Generates an string of the dimensions of the scalar_unit, with the same format as the initialization string of dimensions.
 
dimension::type get_single_dimension_type () const
 Returns the dimension::type if there's only one dimension, returns dimension::NONE if there's more than one dimension or if the dimensions are empty.
 
vector< dimensionget_base_dimensions () const
 Generates a set of the base dimensions of the dimensions of the scalar_unit.
 
const vector< dimension > & get_dimensions () const
 Read-only getter of the dimensions.
 
const floatget_value () const
 Read-only getter of the value.
 
string display (int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
 Generates a string representation of the scalar_unit, with the value and the dimensions. The dimensions can be enclosed by brackets, and the value can be set to have the closest prefix.
 
string base_display (int number_of_decimals=2, bool with_brackets=false, bool use_close_prefix=false) const
 Generates a string representation of the scalar_unit, with its dimensions converted to their base counterpart.
 
string custom_display (const string &init_dimensions, int number_of_decimals=2, bool with_brackets=false) const
 Generates a string representation of the scalar_unit, with the dimensions changed to any set of dimensions, specified by an initialization string of dimensions.
 
string to_latex (const string &init_dimensions, int number_of_decimals=2, bool with_brackets=false) const
 

Protected Member Functions

void add_dimension (const dimension &new_dimension)
 Internal function. It adds a dimension, changing the value according to the conversion factor of the added dimension and the prefix.
 
void remove_dimension (const dimension &old_dimension)
 Internal function. It removes a dimension, changing the value according to the conversion factor of the removed dimension and the prefix.
 
void initialize_from_string (string init_scalar, const vector< dimension > &real_dimensions)
 Internal function. It sets the value and the dimensions of the scalar_unit to the value and dimensions specified by the initialization string of scalar_unit.
 
void check_dimensions (const vector< dimension > &real_dimensions)
 

Protected Attributes

vector< dimensiondimensions
 Dimensions of the scalar_unit. They can be simple dimensions, composite dimensions or special names.
 
float value
 Value of the scalar_unit. It changes automatically when the dimensions change.
 

Detailed Description

Class that allows to create scalar units, which are composed of a value (as a float) and dimensions. The dimensions can be of any number, and be simple dimensions, composite dimensions and/or special names of dimensions. All base and derived scalar unit classes inherit from scalar_unit. Initialization string example: "1 N".

scalar_unit is a class that allows to have a scalar unit, which is composed of a value and one or more dimensions. All dimensions of the SI system of units are supported, and also all of its special names. The special names can be converted to its equivalent dimensions, too. scalar_unit classes have operators with all numeric types, and have operators with themselves. They can be displayed by its dimensions, its base dimensions, or any custom combination of dimensions. When they change dimensions, like, for example, from meters to kilometers, their numeric value is changed accordingly. POSSIBLE FEATURES At the present scalar_unit classes use a vector<dimension> to allow to have any number of dimensions, which can be simple, composite or special names. In order to size less, it's possible for some scalar_unit classes to have only one dimension, instead of a vector, that saves memory. With that approach, the dimension needs only 3 bytes. The possibility to switch between a single dimension and a vector<dimension> doesn't yet exists in C++, and so this important feature has been postposed.

Definition at line 201 of file scalar_unit.hpp.

Constructor & Destructor Documentation

◆ scalar_unit() [1/16]

scalar_unit::scalar_unit ( )

Default constructor, the value is 0 and the dimensions are empty.

Definition at line 23 of file scalar_unit.cpp.

23 : dimensions(),value(0.0f)
24 {}
vector< dimension > dimensions
Dimensions of the scalar_unit. They can be simple dimensions, composite dimensions or special names.
float value
Value of the scalar_unit. It changes automatically when the dimensions change.

◆ scalar_unit() [2/16]

scalar_unit::scalar_unit ( const scalar_unit x)

Copy constructor, copies the value and the dimensions.

Parameters
xscalar_unit to be copied.

Definition at line 26 of file scalar_unit.cpp.

26 : dimensions(x.get_dimensions()),value(x.get_value())
27 {}

◆ scalar_unit() [3/16]

scalar_unit::scalar_unit ( scalar_unit &&  x)

Move constructor, moves the value and the dimensions.

Parameters
xscalar_unit to be moved.

Definition at line 29 of file scalar_unit.cpp.

29 : dimensions(std::move(x.get_dimensions())),value(std::move(x.get_value()))
30 {}

◆ scalar_unit() [4/16]

scifir::scalar_unit::scalar_unit ( float  new_value,
dimension::type  new_dimension,
prefix::type  new_prefix,
dimension::position  new_position = dimension::NUMERATOR 
)
explicit

Definition at line 32 of file scalar_unit.cpp.

32 : dimensions({ dimension(new_dimension,new_prefix,new_position) }),value(new_value)
33 {}

◆ scalar_unit() [5/16]

scifir::scalar_unit::scalar_unit ( double  new_value,
dimension::type  new_dimension,
prefix::type  new_prefix,
dimension::position  new_position = dimension::NUMERATOR 
)
explicit

Definition at line 35 of file scalar_unit.cpp.

35 : dimensions({ dimension(new_dimension,new_prefix,new_position) }),value(float(new_value))
36 {}

◆ scalar_unit() [6/16]

scifir::scalar_unit::scalar_unit ( long double  new_value,
dimension::type  new_dimension,
prefix::type  new_prefix,
dimension::position  new_position = dimension::NUMERATOR 
)
explicit

Definition at line 38 of file scalar_unit.cpp.

38 : dimensions({ dimension(new_dimension,new_prefix,new_position) }),value(float(new_value))
39 {}

◆ scalar_unit() [7/16]

scifir::scalar_unit::scalar_unit ( int  new_value,
dimension::type  new_dimension,
prefix::type  new_prefix,
dimension::position  new_position = dimension::NUMERATOR 
)
explicit

Definition at line 41 of file scalar_unit.cpp.

41 : dimensions({ dimension(new_dimension,new_prefix,new_position) }),value(float(new_value))
42 {}

◆ scalar_unit() [8/16]

scalar_unit::scalar_unit ( float  new_value,
const string init_dimensions 
)
explicit

Creates a new scalar_unit with the value and with the dimensions specified in the string.

Definition at line 44 of file scalar_unit.cpp.

44 : dimensions(create_dimensions(init_dimensions)),value(new_value)
45 {}
vector< dimension > create_dimensions(string init_dimensions)
Creates the dimensions from an initialization string of dimensions.

◆ scalar_unit() [9/16]

scalar_unit::scalar_unit ( double  new_value,
const string init_dimensions 
)
explicit

Creates a new scalar_unit, the double is casted to a float.

Definition at line 47 of file scalar_unit.cpp.

47 : dimensions(create_dimensions(init_dimensions)),value(float(new_value))
48 {}

◆ scalar_unit() [10/16]

scalar_unit::scalar_unit ( long double  new_value,
const string init_dimensions 
)
explicit

Creates a new scalar_unit, the long double is casted to a float.

Definition at line 50 of file scalar_unit.cpp.

50 : dimensions(create_dimensions(init_dimensions)),value(float(new_value))
51 {}

◆ scalar_unit() [11/16]

scalar_unit::scalar_unit ( int  new_value,
const string init_dimensions 
)
explicit

Creates a new scalar_unit, the int is casted to a float.

Definition at line 53 of file scalar_unit.cpp.

53 : dimensions(create_dimensions(init_dimensions)),value(float(new_value))
54 {}

◆ scalar_unit() [12/16]

scalar_unit::scalar_unit ( float  new_value,
const vector< dimension > &  new_dimensions 
)
explicit

Creates a new scalar_unit with the value given and copying the dimensions.

Definition at line 56 of file scalar_unit.cpp.

56 : dimensions(new_dimensions),value(new_value)
57 {}

◆ scalar_unit() [13/16]

scalar_unit::scalar_unit ( double  new_value,
const vector< dimension > &  new_dimensions 
)
explicit

Creates a new scalar_unit, the double is casted to a float, the dimensions are copied.

Definition at line 59 of file scalar_unit.cpp.

59 : dimensions(new_dimensions),value(float(new_value))
60 {}

◆ scalar_unit() [14/16]

scalar_unit::scalar_unit ( long double  new_value,
const vector< dimension > &  new_dimensions 
)
explicit

Creates a new scalar_unit, the long double is casted to a float, the dimensions are copied.

Definition at line 62 of file scalar_unit.cpp.

62 : dimensions(new_dimensions),value(float(new_value))
63 {}

◆ scalar_unit() [15/16]

scalar_unit::scalar_unit ( int  new_value,
const vector< dimension > &  new_dimensions 
)
explicit

Creates a new scalar_unit, the int is casted to a float, the dimensions are copied.

Definition at line 65 of file scalar_unit.cpp.

65 : dimensions(new_dimensions),value(float(new_value))
66 {}

◆ scalar_unit() [16/16]

scalar_unit::scalar_unit ( const string init_scalar)
explicit

Creates a new scalar_unit, the initialization string specifies both the value and the dimensions.

Definition at line 68 of file scalar_unit.cpp.

68 : scalar_unit()
69 {
70 initialize_from_string(init_scalar,vector<dimension>());
71 }
scalar_unit()
Default constructor, the value is 0 and the dimensions are empty.
void initialize_from_string(string init_scalar, const vector< dimension > &real_dimensions)
Internal function. It sets the value and the dimensions of the scalar_unit to the value and dimension...

Member Function Documentation

◆ add_dimension()

void scalar_unit::add_dimension ( const dimension new_dimension)
protected

Internal function. It adds a dimension, changing the value according to the conversion factor of the added dimension and the prefix.

Definition at line 664 of file scalar_unit.cpp.

665 {
666 if (new_dimension.dimension_position == dimension::NUMERATOR)
667 {
668 value /= float(new_dimension.get_conversion_factor());
669 value /= float(new_dimension.prefix_math());
670 }
671 else if (new_dimension.dimension_position == dimension::DENOMINATOR)
672 {
673 value *= float(new_dimension.get_conversion_factor());
674 value *= float(new_dimension.prefix_math());
675 }
676 }
@ DENOMINATOR
The dimension is at the denominator.
Definition dimension.hpp:38
@ NUMERATOR
The dimension is at the numerator.
Definition dimension.hpp:38

◆ base_display()

string scalar_unit::base_display ( int  number_of_decimals = 2,
bool  with_brackets = false,
bool  use_close_prefix = false 
) const

Generates a string representation of the scalar_unit, with its dimensions converted to their base counterpart.

Definition at line 475 of file scalar_unit.cpp.

476 {
477 ostringstream output;
478 long double x_value = get_value();
479 vector<dimension> base_dimensions = create_base_dimensions(dimensions,x_value);
480 if (base_dimensions.size() == 1 and use_close_prefix == true)
481 {
482 int value_scale = int(log10(get_value()));
483 prefix display_prefix = closest_prefix(base_dimensions[0].prefix,value_scale);
484 x_value *= base_dimensions[0].prefix_math();
485 x_value /= base_dimensions[0].prefix_math(display_prefix);
486 vector<dimension> x_dimensions = base_dimensions;
487 x_dimensions[0].prefix = display_prefix;
488 output << display_float(float(x_value),number_of_decimals) << " " << to_string(base_dimensions,with_brackets);
489 }
490 else
491 {
492 output << display_float(float(x_value),number_of_decimals) << " " << to_string(base_dimensions,with_brackets);
493 }
494 return output.str();
495 }
const float & get_value() const
Read-only getter of the value.
prefix closest_prefix(const prefix &actual_prefix, int actual_scale)
Returns the closes prefix related to the scale of the current value. It is used when displaying a sca...
Definition prefix.cpp:323
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582
string display_float(const float &value, int number_of_decimals)
Definition types.cpp:36
vector< dimension > create_base_dimensions(const string &init_dimensions)
Creates the base dimensions from an initialization string of dimensions.

◆ change_dimensions() [1/2]

void scalar_unit::change_dimensions ( const scalar_unit x)

Changes the dimensions to the same dimensions of the scalar_unit.

Definition at line 287 of file scalar_unit.cpp.

288 {
289 if(has_dimensions(x.get_dimensions()))
290 {
291 if (equal_dimensions_and_prefixes(dimensions,x.get_dimensions()))
292 {
293 return;
294 }
295 for(const dimension& actual_dimension : dimensions)
296 {
297 remove_dimension(actual_dimension);
298 if(actual_dimension.is_composite_dimension())
299 {
300 vector<dimension> base_dimensions = actual_dimension.get_base_dimensions();
301 for(const dimension& base_dimension : base_dimensions)
302 {
303 remove_dimension(base_dimension);
304 }
305 }
306 }
307 if (dimensions.size() == 1 and x.get_dimensions().size() == 1)
308 {
309 if (dimensions[0].dimension_type == dimension::CELSIUS and dimensions[0].dimension_position == dimension::NUMERATOR and x.get_dimensions()[0].dimension_type == dimension::KELVIN and x.get_dimensions()[0].dimension_position == dimension::NUMERATOR)
310 {
311 value += 273.15f;
312 }
313 else if (dimensions[0].dimension_type == dimension::KELVIN and dimensions[0].dimension_position == dimension::NUMERATOR and x.get_dimensions()[0].dimension_type == dimension::CELSIUS and x.get_dimensions()[0].dimension_position == dimension::NUMERATOR)
314 {
315 value -= 273.15f;
316 }
317 }
318 dimensions.clear();
319 for(const dimension& new_dimension : x.get_dimensions())
320 {
321 add_dimension(new_dimension);
322 if(new_dimension.is_composite_dimension())
323 {
324 vector<dimension> new_base_dimensions = new_dimension.get_base_dimensions();
325 for(const dimension& new_base_dimension : new_base_dimensions)
326 {
327 add_dimension(new_base_dimension);
328 }
329 }
330 }
331 dimensions = x.get_dimensions();
332 }
333 else
334 {
335 cerr << "Cannot change to different base dimensions" << endl;
336 }
337 }
@ CELSIUS
Celsius, plural celsius. SI dimension of temperature, derived from kelvin. Symbol °C....
Definition dimension.hpp:35
@ KELVIN
Kelvin, plural kelvins. SI dimension of temperature. Symbol K.
Definition dimension.hpp:35
void add_dimension(const dimension &new_dimension)
Internal function. It adds a dimension, changing the value according to the conversion factor of the ...
const vector< dimension > & get_dimensions() const
Read-only getter of the dimensions.
bool has_dimensions(const string &init_dimensions) const
Checks if the basic dimensions are the same as the initialization string of dimensions.
void remove_dimension(const dimension &old_dimension)
Internal function. It removes a dimension, changing the value according to the conversion factor of t...
bool equal_dimensions_and_prefixes(const vector< dimension > &x, const vector< dimension > &y)
Checks if the base dimensions of two vectors of dimensions are equal, and if they have also the same ...

◆ change_dimensions() [2/2]

void scalar_unit::change_dimensions ( const string init_dimensions)

Changes the dimensions to the dimensions specified by the initialization string of dimensions.

Definition at line 234 of file scalar_unit.cpp.

235 {
236 vector<dimension> new_dimensions = create_dimensions(init_dimensions);
237 if(has_dimensions(new_dimensions))
238 {
239 if (equal_dimensions_and_prefixes(dimensions,new_dimensions))
240 {
241 return;
242 }
243 for(const dimension& actual_dimension : dimensions)
244 {
245 remove_dimension(actual_dimension);
246 if(actual_dimension.is_composite_dimension())
247 {
248 vector<dimension> base_dimensions = actual_dimension.get_base_dimensions();
249 for(const dimension& base_dimension : base_dimensions)
250 {
251 remove_dimension(base_dimension);
252 }
253 }
254 }
255 if (dimensions.size() == 1)
256 {
257 if (dimensions[0].dimension_type == dimension::CELSIUS and dimensions[0].dimension_position == dimension::NUMERATOR and new_dimensions[0].dimension_type == dimension::KELVIN and new_dimensions[0].dimension_position == dimension::NUMERATOR)
258 {
259 value += 273.15f;
260 }
261 else if (dimensions[0].dimension_type == dimension::KELVIN and dimensions[0].dimension_position == dimension::NUMERATOR and new_dimensions[0].dimension_type == dimension::CELSIUS and new_dimensions[0].dimension_position == dimension::NUMERATOR)
262 {
263 value -= 273.15f;
264 }
265 }
266 dimensions.clear();
267 for(const dimension& new_dimension : new_dimensions)
268 {
269 add_dimension(new_dimension);
270 if(new_dimension.is_composite_dimension())
271 {
272 vector<dimension> new_base_dimensions = new_dimension.get_base_dimensions();
273 for(const dimension& new_base_dimension : new_base_dimensions)
274 {
275 add_dimension(new_base_dimension);
276 }
277 }
278 }
279 dimensions = new_dimensions;
280 }
281 else
282 {
283 cerr << "Cannot change to different base dimensions" << endl;
284 }
285 }

◆ check_dimensions()

void scifir::scalar_unit::check_dimensions ( const vector< dimension > &  real_dimensions)
protected

Definition at line 731 of file scalar_unit.cpp.

732 {
733 if (!has_dimensions(real_dimensions))
734 {
735 value = 0;
736 dimensions.clear();
737 }
738 }

◆ custom_display()

string scalar_unit::custom_display ( const string init_dimensions,
int  number_of_decimals = 2,
bool  with_brackets = false 
) const

Generates a string representation of the scalar_unit, with the dimensions changed to any set of dimensions, specified by an initialization string of dimensions.

Definition at line 497 of file scalar_unit.cpp.

498 {
499 ostringstream output;
500 long double new_value = get_value();
501 if (init_dimensions != "sci")
502 {
503 for(const dimension& x_dimension : dimensions)
504 {
505 if (x_dimension.dimension_position == dimension::NUMERATOR)
506 {
507 new_value *= x_dimension.get_conversion_factor();
508 new_value *= x_dimension.prefix_math();
509 }
510 else if (x_dimension.dimension_position == dimension::DENOMINATOR)
511 {
512 new_value /= x_dimension.get_conversion_factor();
513 new_value /= x_dimension.prefix_math();
514 }
515 }
516 vector<dimension> base_dimensions = create_base_dimensions(dimensions);
517 for(const dimension& x_dimension : base_dimensions)
518 {
519 if (x_dimension.dimension_position == dimension::NUMERATOR)
520 {
521 new_value *= x_dimension.prefix_math();
522 }
523 else if (x_dimension.dimension_position == dimension::DENOMINATOR)
524 {
525 new_value /= x_dimension.prefix_math();
526 }
527 }
528 vector<dimension> new_dimensions = create_dimensions(init_dimensions);
529 if (dimensions.size() == 1 and new_dimensions.size() == 1)
530 {
531 if (dimensions[0].dimension_type == dimension::CELSIUS and dimensions[0].dimension_position == dimension::NUMERATOR and new_dimensions[0].dimension_type == dimension::KELVIN and new_dimensions[0].dimension_position == dimension::NUMERATOR)
532 {
533 new_value += 273.15l;
534 }
535 else if (dimensions[0].dimension_type == dimension::KELVIN and dimensions[0].dimension_position == dimension::NUMERATOR and new_dimensions[0].dimension_type == dimension::CELSIUS and new_dimensions[0].dimension_position == dimension::NUMERATOR)
536 {
537 new_value -= 273.15l;
538 }
539 }
540 for(const dimension& x_new_dimension : new_dimensions)
541 {
542 if (x_new_dimension.dimension_position == dimension::NUMERATOR)
543 {
544 new_value /= x_new_dimension.get_conversion_factor();
545 new_value /= x_new_dimension.prefix_math();
546 }
547 else if (x_new_dimension.dimension_position == dimension::DENOMINATOR)
548 {
549 new_value *= x_new_dimension.get_conversion_factor();
550 new_value *= x_new_dimension.prefix_math();
551 }
552 }
553 output << display_float(float(new_value),number_of_decimals) << " ";
554 if (with_brackets)
555 {
556 output << "[";
557 }
558 output << init_dimensions;
559 if (with_brackets)
560 {
561 output << "]";
562 }
563 }
564 else
565 {
566 for (const dimension& x_dimension : dimensions)
567 {
568 new_value *= x_dimension.prefix_math();
569 }
570 vector<dimension> new_dimensions = dimensions;
571 for (dimension& x_new_dimension : new_dimensions)
572 {
573 x_new_dimension.prefix.prefix_type = prefix::NONE;
574 }
575 int value_scale = int(log10(get_value()));
576 output << display_float(float(new_value / std::pow(10,value_scale)),number_of_decimals) << "e" << value_scale << " " << to_string(new_dimensions,with_brackets);
577 }
578 return output.str();
579 }
@ NONE
There is no prefix. Then, the dimension is not increased or decreased by some factor.
Definition prefix.hpp:16

◆ display()

string scalar_unit::display ( int  number_of_decimals = 2,
bool  with_brackets = false,
bool  use_close_prefix = false 
) const

Generates a string representation of the scalar_unit, with the value and the dimensions. The dimensions can be enclosed by brackets, and the value can be set to have the closest prefix.

Definition at line 446 of file scalar_unit.cpp.

447 {
448 ostringstream output;
449 if (dimensions.size() == 1 and use_close_prefix == true)
450 {
451 prefix display_prefix;
452 if (get_value() != 0)
453 {
454 int value_scale = int(log10(get_value()));
455 display_prefix = closest_prefix(dimensions[0].prefix,value_scale);
456 }
457 else
458 {
459 display_prefix = dimensions[0].prefix;
460 }
461 long double x_value = get_value();
462 x_value *= dimensions[0].prefix_math();
463 x_value /= dimensions[0].prefix_math(display_prefix);
464 vector<dimension> x_dimensions = dimensions;
465 x_dimensions[0].prefix = display_prefix;
466 output << display_float(float(x_value),number_of_decimals) << " " << to_string(x_dimensions,with_brackets);
467 }
468 else
469 {
470 output << display_float(get_value(),number_of_decimals) << " " << to_string(dimensions,with_brackets);
471 }
472 return output.str();
473 }

◆ display_dimensions()

string scalar_unit::display_dimensions ( ) const

Generates an string of the dimensions of the scalar_unit, with the same format as the initialization string of dimensions.

Definition at line 419 of file scalar_unit.cpp.

420 {
421 return to_string(dimensions);
422 }

◆ get_base_dimensions()

vector< dimension > scalar_unit::get_base_dimensions ( ) const

Generates a set of the base dimensions of the dimensions of the scalar_unit.

Definition at line 441 of file scalar_unit.cpp.

442 {
444 }

◆ get_dimensions()

const vector< dimension > & scalar_unit::get_dimensions ( ) const
inline

Read-only getter of the dimensions.

Definition at line 321 of file scalar_unit.hpp.

322 {
323 return dimensions;
324 }

◆ get_single_dimension_type()

dimension::type scalar_unit::get_single_dimension_type ( ) const

Returns the dimension::type if there's only one dimension, returns dimension::NONE if there's more than one dimension or if the dimensions are empty.

Definition at line 429 of file scalar_unit.cpp.

430 {
431 if (dimensions.size() == 1)
432 {
433 return dimensions[0].dimension_type;
434 }
435 else
436 {
437 return dimension::NONE;
438 }
439 }
@ NONE
No dimension. Default value for the default constructor.
Definition dimension.hpp:35

◆ get_value()

const float & scalar_unit::get_value ( ) const
inline

Read-only getter of the value.

Definition at line 326 of file scalar_unit.hpp.

327 {
328 return value;
329 }

◆ has_composite_dimensions()

bool scalar_unit::has_composite_dimensions ( ) const

Returns true is there's more than one simple dimension.

Definition at line 403 of file scalar_unit.cpp.

404 {
405 if (dimensions.size() == 0)
406 {
407 return false;
408 }
409 else if (dimensions.size() == 1)
410 {
411 return dimensions[0].is_composite_dimension();
412 }
413 else
414 {
415 return true;
416 }
417 }

◆ has_dimensions() [1/3]

bool scalar_unit::has_dimensions ( const scalar_unit x) const

Checks if the basic dimensions are the same as other scalar_unit.

Definition at line 350 of file scalar_unit.cpp.

351 {
352 return equal_dimensions(dimensions,x.get_dimensions());
353 }
bool equal_dimensions(const string &init_dimensions_x, const string &init_dimensions_y)
Checks if two initialization strings of dimensions initialize the same basic dimensions.

◆ has_dimensions() [2/3]

bool scalar_unit::has_dimensions ( const string init_dimensions) const

Checks if the basic dimensions are the same as the initialization string of dimensions.

Definition at line 339 of file scalar_unit.cpp.

340 {
341 vector<dimension> structure_dimensions = create_dimensions(init_dimensions);
342 return has_dimensions(structure_dimensions);
343 }

◆ has_dimensions() [3/3]

bool scalar_unit::has_dimensions ( const vector< dimension > &  x_dimensions) const

Checks if the basic dimensions are the same as some set of dimensions.

Definition at line 345 of file scalar_unit.cpp.

346 {
347 return equal_dimensions(dimensions,x_dimensions);
348 }

◆ has_empty_dimensions()

bool scalar_unit::has_empty_dimensions ( ) const

Checks if there aren't base dimensions.

Definition at line 355 of file scalar_unit.cpp.

356 {
357 if(dimensions.size() == 0)
358 {
359 return true;
360 }
361 else
362 {
363 return false;
364 }
365 }

◆ has_simple_dimensions()

bool scalar_unit::has_simple_dimensions ( ) const

Returns true if there's only a simple dimension.

Definition at line 386 of file scalar_unit.cpp.

387 {
388 if (dimensions.size() == 1)
389 {
390 return dimensions[0].is_simple_dimension();
391 }
392 else
393 {
394 return false;
395 }
396 }

◆ has_single_dimensions()

bool scalar_unit::has_single_dimensions ( ) const

Returns true if there's only one dimension, which can be simple or composite.

Definition at line 398 of file scalar_unit.cpp.

399 {
400 return (dimensions.size() == 1);
401 }

◆ initialize_from_string()

void scalar_unit::initialize_from_string ( string  init_scalar,
const vector< dimension > &  real_dimensions 
)
protected

Internal function. It sets the value and the dimensions of the scalar_unit to the value and dimensions specified by the initialization string of scalar_unit.

Definition at line 692 of file scalar_unit.cpp.

693 {
694 if(!isdigit(init_scalar[0]))
695 {
696 return;
697 }
698 else
699 {
700 int i = 0;
701 while(isdigit(init_scalar[i]) || init_scalar[i] == '.' || init_scalar[i] == ' ' || init_scalar[i] == '*' || init_scalar[i] == '^' || init_scalar[i] == 'e' || init_scalar[i] == 'E')
702 {
703 if (init_scalar[i] == ' ')
704 {
705 break;
706 }
707 i++;
708 }
709 string string_value = init_scalar.substr(0, i);
710 boost::algorithm::erase_all(string_value, " ");
711 size_t search_e = string_value.find("E");
712 if (search_e != string::npos)
713 {
714 string_value.replace(search_e,1,"e");
715 }
716 size_t search_10 = string_value.find("*10^");
717 if (search_10 != string::npos)
718 {
719 string_value.replace(search_10,4,"e");
720 }
721 const vector<dimension> new_dimensions = create_dimensions(init_scalar.substr(i));
722 if (real_dimensions.size() == 0 or equal_dimensions(new_dimensions,real_dimensions))
723 {
724 stringstream ss(string_value);
725 ss >> value;
726 dimensions = new_dimensions;
727 }
728 }
729 }

◆ is_dimensionless()

bool scalar_unit::is_dimensionless ( ) const

Returns true if there aren't dimensions or if all dimensions are dimensionless.

Definition at line 367 of file scalar_unit.cpp.

368 {
370 {
371 return true;
372 }
373 else
374 {
375 for (const dimension& x : dimensions)
376 {
377 if (!x.is_dimensionless())
378 {
379 return false;
380 }
381 }
382 return true;
383 }
384 }
bool has_empty_dimensions() const
Checks if there aren't base dimensions.

◆ operator float()

scalar_unit::operator float ( ) const
explicit

Cast the scalar_unit to their float equivalent, it discards the dimensions and copies the value to a float.

Definition at line 107 of file scalar_unit.cpp.

108 {
109 return value;
110 }

◆ operator*() [1/2]

scalar_unit scalar_unit::operator* ( scalar_unit  x) const

Multiplication operator, it multiplies two scalar_unit classes, their dimensions are also multiplied.

Definition at line 157 of file scalar_unit.cpp.

158 {
159 long double new_value = value;
160 new_value *= x.get_value();
161 vector<dimension> new_dimensions = multiply_dimensions(get_dimensions(),x.get_dimensions(),new_value);
162 return scalar_unit(new_value, new_dimensions);
163 }
vector< dimension > multiply_dimensions(const vector< dimension > &x, const vector< dimension > &y)
Multiplies two vectors of dimensions. The result is normalized after, which means that equal dimensio...

◆ operator*() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit scalar_unit::operator* ( T  y) const
inline

Multiplication operator, it multiplies the numeric type with the value, independent of the dimensions.

Definition at line 254 of file scalar_unit.hpp.

255 {
256 scalar_unit x = *this;
257 x *= y;
258 return x;
259 }

◆ operator*=()

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

Multiplication operator, it multiplies the numeric type to the value, independent of the dimensions.

Definition at line 288 of file scalar_unit.hpp.

289 {
290 value *= y;
291 }

◆ operator+() [1/2]

scalar_unit scalar_unit::operator+ ( scalar_unit  x) const

Addition operator, it sums two scalar_unit classes, their dimensions are changed to be equal first. If the basic dimensions are different, it returns an empty scalar_unit class.

Definition at line 125 of file scalar_unit.cpp.

126 {
127 if(has_dimensions(x))
128 {
129 x.change_dimensions(*this);
130 scalar_unit a = *this;
131 a += x.get_value();
132 return a;
133 }
134 else
135 {
136 cerr << "Cannot sum different dimensions" << endl;
137 return scalar_unit();
138 }
139 }

◆ operator+() [2/2]

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

Addition operator, it sums the numeric type to the value, independent of the dimensions.

Definition at line 238 of file scalar_unit.hpp.

239 {
240 scalar_unit x = *this;
241 x += y;
242 return x;
243 }

◆ operator++() [1/2]

scalar_unit & scalar_unit::operator++ ( )

Increment operator, it increases the value by one.

Definition at line 208 of file scalar_unit.cpp.

209 {
210 value++;
211 return *this;
212 }

◆ operator++() [2/2]

scalar_unit & scalar_unit::operator++ ( int  )

Increment operator, it increases the value by one.

Definition at line 214 of file scalar_unit.cpp.

215 {
216 scalar_unit& tmp(*this);
217 operator ++();
218 return tmp;
219 }
scalar_unit & operator++()
Increment operator, it increases the value by one.

◆ operator+=() [1/2]

void scalar_unit::operator+= ( scalar_unit  x)

Addition operator, it adds a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't sums to the value.

Definition at line 186 of file scalar_unit.cpp.

187 {
188 if(!has_dimensions(x))
189 {
190 cerr << "Cannot sum different dimensions" << endl;
191 return;
192 }
193 x.change_dimensions(*this);
194 value += x.get_value();
195 }

◆ operator+=() [2/2]

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

Addition operator, it adds the numeric type to the value, independent of the dimensions.

Definition at line 276 of file scalar_unit.hpp.

277 {
278 value += y;
279 }

◆ operator-() [1/2]

scalar_unit scalar_unit::operator- ( scalar_unit  x) const

Substraction operator, it substracts one scalar_unit from the other, their dimensions are changed to be equal first. If the basic dimensions are different, it returns an empty scalar_unit class.

Definition at line 141 of file scalar_unit.cpp.

142 {
143 if(has_dimensions(x))
144 {
145 x.change_dimensions(*this);
146 scalar_unit a = *this;
147 a -= x.get_value();
148 return a;
149 }
150 else
151 {
152 cerr << "Cannot substract different dimensions" << endl;
153 return scalar_unit();
154 }
155 }

◆ operator-() [2/2]

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

Substraction operator, it substracts the numeric type to the value, independent of the dimensions.

Definition at line 246 of file scalar_unit.hpp.

247 {
248 scalar_unit x = *this;
249 x -= y;
250 return x;
251 }

◆ operator--() [1/2]

scalar_unit & scalar_unit::operator-- ( )

Decrement operator, it decreases the value by one.

Definition at line 221 of file scalar_unit.cpp.

222 {
223 value--;
224 return *this;
225 }

◆ operator--() [2/2]

scalar_unit & scalar_unit::operator-- ( int  )

Decrement operator, it decreases the value by one.

Definition at line 227 of file scalar_unit.cpp.

228 {
229 scalar_unit& tmp(*this);
230 operator --();
231 return tmp;
232 }
scalar_unit & operator--()
Decrement operator, it decreases the value by one.

◆ operator-=() [1/2]

void scalar_unit::operator-= ( scalar_unit  x)

Substraction operator, it substracts a scalar_unit class to another, by converting their dimensions to be equal first. If their basic dimensions are different, it doesn't substracts to the value.

Definition at line 197 of file scalar_unit.cpp.

198 {
199 if(!has_dimensions(x))
200 {
201 cerr << "Cannot substract different dimensions" << endl;
202 return;
203 }
204 x.change_dimensions(*this);
205 value -= x.get_value();
206 }

◆ operator-=() [2/2]

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

Substraction operator, it substracts the numeric type to the value, independent of the dimensions.

Definition at line 282 of file scalar_unit.hpp.

283 {
284 value -= y;
285 }

◆ operator/() [1/2]

scalar_unit scalar_unit::operator/ ( scalar_unit  x) const

Division operator, it divides one scalar_unit class with the other, their dimensions are also divided.

Definition at line 165 of file scalar_unit.cpp.

166 {
167 long double new_value = value;
168 new_value /= x.get_value();
169 vector<dimension> new_dimensions = divide_dimensions(get_dimensions(),x.get_dimensions(),new_value);
170 return scalar_unit(new_value, new_dimensions);
171 }
vector< dimension > divide_dimensions(vector< dimension > x, const vector< dimension > &y, long double &value)
Divides the first vector of dimensions with the other. The result is normalized after,...

◆ operator/() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scalar_unit scalar_unit::operator/ ( T  y) const
inline

Division operator, it divides the value with the numeric type, independent of the dimensions.

Definition at line 262 of file scalar_unit.hpp.

263 {
264 scalar_unit x = *this;
265 x /= y;
266 return x;
267 }

◆ operator/=()

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

Division operator, it divides the numeric type to the value, independent of the dimensions.

Definition at line 294 of file scalar_unit.hpp.

295 {
296 value /= y;
297 }

◆ operator=() [1/3]

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

Copy assignment, it assigns a copy of the scalar_unit.

Definition at line 73 of file scalar_unit.cpp.

74 {
75 if (has_dimensions(x))
76 {
77 dimensions = x.get_dimensions();
78 value = x.get_value();
79 }
80 else
81 {
82 cerr << "Cannot initialize to different dimensions" << endl;
83 }
84 return *this;
85 }

◆ operator=() [2/3]

scalar_unit & scalar_unit::operator= ( const string init_scalar)

Assignment with an initialization string, the value and the dimensions are both specified.

Definition at line 101 of file scalar_unit.cpp.

102 {
103 initialize_from_string(init_scalar,vector<dimension>());
104 return *this;
105 }

◆ operator=() [3/3]

scalar_unit & scalar_unit::operator= ( scalar_unit &&  x)

Move assignment, it moves the scalar_unit.

Definition at line 87 of file scalar_unit.cpp.

88 {
89 if (has_dimensions(x))
90 {
91 dimensions = std::move(x.get_dimensions());
92 value = std::move(x.get_value());
93 }
94 else
95 {
96 cerr << "Cannot initialize to different dimensions" << endl;
97 }
98 return *this;
99 }

◆ operator==()

bool scalar_unit::operator== ( scalar_unit  x) const

Comparison operator, two scalar_unit classes are considered equivalent if they have the same value given the same dimensions.

Definition at line 112 of file scalar_unit.cpp.

113 {
114 x.change_dimensions(*this);
115 if(get_value() == x.get_value() and has_dimensions(x))
116 {
117 return true;
118 }
119 else
120 {
121 return false;
122 }
123 }

◆ operator^() [1/2]

scalar_unit scalar_unit::operator^ ( const scalar_unit x) const

Power operator, it powers a scalar_unit class with another, if that second scalar_unit class, which is the exponent, as empty dimensions. If the exponent doesn't has empty dimensions it returns an empty scalar_unit class.

Definition at line 173 of file scalar_unit.cpp.

174 {
175 if(x.has_empty_dimensions())
176 {
177 return scalar_unit(std::pow(value,x.get_value()),power_dimensions(get_dimensions(),int(x.get_value())));
178 }
179 else
180 {
181 cerr << "Exponent with dimensions doesn't exist" << endl;
182 return scalar_unit();
183 }
184 }
vector< dimension > power_dimensions(const vector< dimension > &x, int exponent)
Powers the dimensions by an exponent.

◆ operator^() [2/2]

template<typename T , typename = typename enable_if<is_integer_number<T>::value>::type>
scalar_unit scalar_unit::operator^ ( T  y) const
inline

Power operator, it powers the value with the numeric type, independent of the dimensions.

Definition at line 270 of file scalar_unit.hpp.

271 {
272 return scalar_unit(std::pow(get_value(),y),power_dimensions(get_dimensions(),y));
273 }

◆ remove_dimension()

void scalar_unit::remove_dimension ( const dimension old_dimension)
protected

Internal function. It removes a dimension, changing the value according to the conversion factor of the removed dimension and the prefix.

Definition at line 678 of file scalar_unit.cpp.

679 {
680 if (old_dimension.dimension_position == dimension::NUMERATOR)
681 {
682 value *= float(old_dimension.get_conversion_factor());
683 value *= float(old_dimension.prefix_math());
684 }
685 else if (old_dimension.dimension_position == dimension::DENOMINATOR)
686 {
687 value /= float(old_dimension.get_conversion_factor());
688 value /= float(old_dimension.prefix_math());
689 }
690 }

◆ to_latex()

string scifir::scalar_unit::to_latex ( const string init_dimensions,
int  number_of_decimals = 2,
bool  with_brackets = false 
) const

Definition at line 581 of file scalar_unit.cpp.

582 {
583 ostringstream output;
584 long double new_value = get_value();
585 if (init_dimensions != "sci")
586 {
587 vector<dimension> new_dimensions;
588 if (init_dimensions != "")
589 {
590 for(const dimension& x_dimension : dimensions)
591 {
592 if (x_dimension.dimension_position == dimension::NUMERATOR)
593 {
594 new_value *= x_dimension.get_conversion_factor();
595 new_value *= x_dimension.prefix_math();
596 }
597 else if (x_dimension.dimension_position == dimension::DENOMINATOR)
598 {
599 new_value /= x_dimension.get_conversion_factor();
600 new_value /= x_dimension.prefix_math();
601 }
602 }
603 vector<dimension> base_dimensions = create_base_dimensions(dimensions);
604 for(const dimension& x_dimension : base_dimensions)
605 {
606 if (x_dimension.dimension_position == dimension::NUMERATOR)
607 {
608 new_value *= x_dimension.prefix_math();
609 }
610 else if (x_dimension.dimension_position == dimension::DENOMINATOR)
611 {
612 new_value /= x_dimension.prefix_math();
613 }
614 }
615 new_dimensions = create_dimensions(init_dimensions);
616 if (dimensions.size() == 1 and new_dimensions.size() == 1)
617 {
618 if (dimensions[0].dimension_type == dimension::CELSIUS and dimensions[0].dimension_position == dimension::NUMERATOR and new_dimensions[0].dimension_type == dimension::KELVIN and new_dimensions[0].dimension_position == dimension::NUMERATOR)
619 {
620 new_value += 273.15l;
621 }
622 else if (dimensions[0].dimension_type == dimension::KELVIN and dimensions[0].dimension_position == dimension::NUMERATOR and new_dimensions[0].dimension_type == dimension::CELSIUS and new_dimensions[0].dimension_position == dimension::NUMERATOR)
623 {
624 new_value -= 273.15l;
625 }
626 }
627 for(const dimension& x_new_dimension : new_dimensions)
628 {
629 if (x_new_dimension.dimension_position == dimension::NUMERATOR)
630 {
631 new_value /= x_new_dimension.get_conversion_factor();
632 new_value /= x_new_dimension.prefix_math();
633 }
634 else if (x_new_dimension.dimension_position == dimension::DENOMINATOR)
635 {
636 new_value *= x_new_dimension.get_conversion_factor();
637 new_value *= x_new_dimension.prefix_math();
638 }
639 }
640 }
641 else
642 {
643 new_dimensions = dimensions;
644 }
645 output << display_float(float(new_value),number_of_decimals) << " " << scifir::to_latex(new_dimensions,with_brackets);
646 }
647 else
648 {
649 for (const dimension& x_dimension : dimensions)
650 {
651 new_value *= x_dimension.prefix_math();
652 }
653 vector<dimension> new_dimensions = dimensions;
654 for (dimension& x_new_dimension : new_dimensions)
655 {
656 x_new_dimension.prefix.prefix_type = prefix::NONE;
657 }
658 int value_scale = int(log10(get_value()));
659 output << display_float(float(new_value / std::pow(10,value_scale)),number_of_decimals) << "e" << value_scale << " " << scifir::to_latex(new_dimensions,with_brackets);
660 }
661 return output.str();
662 }
string to_latex(const vector< dimension > &x_dimensions, bool with_brackets)

Member Data Documentation

◆ dimensions

scalar_unit::dimensions
protected

Dimensions of the scalar_unit. They can be simple dimensions, composite dimensions or special names.

Definition at line 338 of file scalar_unit.hpp.

◆ value

scalar_unit::value
protected

Value of the scalar_unit. It changes automatically when the dimensions change.

Definition at line 339 of file scalar_unit.hpp.


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