6#include "../util/types.hpp"
8#include "boost/algorithm/string/erase.hpp"
9#include "boost/algorithm/string.hpp"
82 cerr <<
"Cannot initialize to different dimensions" <<
endl;
92 value = std::move(x.get_value());
96 cerr <<
"Cannot initialize to different dimensions" <<
endl;
136 cerr <<
"Cannot sum different dimensions" <<
endl;
152 cerr <<
"Cannot substract different dimensions" <<
endl;
181 cerr <<
"Exponent with dimensions doesn't exist" <<
endl;
190 cerr <<
"Cannot sum different dimensions" <<
endl;
201 cerr <<
"Cannot substract different dimensions" <<
endl;
283 cerr <<
"Cannot change to different base dimensions" <<
endl;
335 cerr <<
"Cannot change to different base dimensions" <<
endl;
377 if (!x.is_dimensionless())
411 return dimensions[0].is_composite_dimension();
484 x_value *= base_dimensions[0].prefix_math();
834 values[values.size() - 1] = values[values.size() - 1].substr(0,values[values.size() - 1].size() - 1);
836 if (values.size() == 1)
839 boost::split(
subvalues,values[0],boost::is_any_of(
"*"));
869 else if (values.size() == 2)
871 if (values[0] !=
"1")
874 boost::split(
subvalues,values[0],boost::is_any_of(
"*"));
1023 return !(x == init_scalar);
1040 return !(x > init_scalar);
1045 return !(x < init_scalar);
1050 return (x == init_scalar);
1055 return (x != init_scalar);
1072 return !(init_scalar > x);
1077 return !(init_scalar < x);
1082 ostringstream output;
1089 ostringstream output;
1092 return output.str();
1097 ostringstream output;
1100 return output.str();
1105 return os << to_string(x);
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
position
Represents the position of the dimension, which can be at the numerator or at the denominator....
@ DENOMINATOR
The dimension is at the denominator.
@ NUMERATOR
The dimension is at the numerator.
type
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are su...
@ NONE
No dimension. Default value for the default constructor.
@ CELSIUS
Celsius, plural celsius. SI dimension of temperature, derived from kelvin. Symbol °C....
@ KELVIN
Kelvin, plural kelvins. SI dimension of temperature. Symbol K.
Class that represents prefixes of the SI system of units. Each prefix sizes 1 byte....
type
Represents a prefix of the SI system of units. All the prefixes of the SI system of units are support...
@ NONE
There is no prefix. Then, the dimension is not increased or decreased by some factor.
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....
string to_latex(const string &init_dimensions, int number_of_decimals=2, bool with_brackets=false) const
bool has_single_dimensions() const
Returns true if there's only one dimension, which can be simple or composite.
bool has_empty_dimensions() const
Checks if there aren't base dimensions.
string display_dimensions() const
Generates an string of the dimensions of the scalar_unit, with the same format as the initialization ...
scalar_unit & operator--()
Decrement operator, it decreases the value by one.
bool has_composite_dimensions() const
Returns true is there's more than one simple dimension.
void add_dimension(const dimension &new_dimension)
Internal function. It adds a dimension, changing the value according to the conversion factor of the ...
vector< dimension > dimensions
Dimensions of the scalar_unit. They can be simple dimensions, composite dimensions or special names.
scalar_unit & operator=(const scalar_unit &x)
Copy assignment, it assigns a copy of the scalar_unit.
scalar_unit operator*(scalar_unit x) const
Multiplication operator, it multiplies two scalar_unit classes, their dimensions are also multiplied.
const vector< dimension > & get_dimensions() const
Read-only getter of the dimensions.
bool operator==(scalar_unit x) const
Comparison operator, two scalar_unit classes are considered equivalent if they have the same value gi...
scalar_unit operator/(scalar_unit x) const
Division operator, it divides one scalar_unit class with the other, their dimensions are also divided...
bool has_dimensions(const string &init_dimensions) const
Checks if the basic dimensions are the same as the initialization string of dimensions.
void check_dimensions(const vector< dimension > &real_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 th...
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....
vector< dimension > get_base_dimensions() const
Generates a set of the base dimensions of the dimensions of the scalar_unit.
float value
Value of the scalar_unit. It changes automatically when the dimensions change.
bool is_dimensionless() const
Returns true if there aren't dimensions or if all dimensions are dimensionless.
scalar_unit operator+(scalar_unit x) const
Addition operator, it sums two scalar_unit classes, their dimensions are changed to be equal first....
scalar_unit & operator++()
Increment operator, it increases the value by one.
bool has_simple_dimensions() const
Returns true if there's only a simple dimension.
scalar_unit operator-(scalar_unit x) const
Substraction operator, it substracts one scalar_unit from the other, their dimensions are changed to ...
void change_dimensions(const string &init_dimensions)
Changes the dimensions to the dimensions specified by the initialization string of dimensions.
scalar_unit()
Default constructor, the value is 0 and the dimensions are empty.
void operator+=(scalar_unit x)
Addition operator, it adds a scalar_unit class to another, by converting their dimensions to be equal...
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...
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 dimen...
void operator-=(scalar_unit x)
Substraction operator, it substracts a scalar_unit class to another, by converting their dimensions t...
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 cou...
void remove_dimension(const dimension &old_dimension)
Internal function. It removes a dimension, changing the value according to the conversion factor of t...
const float & get_value() const
Read-only getter of the value.
scalar_unit operator^(const scalar_unit &x) const
Power operator, it powers a scalar_unit class with another, if that second scalar_unit class,...
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
angle sqrt_nth(const angle &x, int index)
Calculates the nth root of the angle x and returns that new angle.
T abs(const complex_number< T > &x)
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.
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,...
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 ...
bool is_scalar_unit(const string &init_scalar)
Checks if an string is an initialization string of a scalar_unit.
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...
scalar_unit pow(const scalar_unit &x, int exponent)
Exponentiates a scalar_unit to some numeric type, the dimensions are also exponentiated.
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
string display_float(const float &value, int number_of_decimals)
vector< dimension > create_base_dimensions(const string &init_dimensions)
Creates the base dimensions from an initialization string of dimensions.
string to_latex(const vector< dimension > &x_dimensions, bool with_brackets)
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...
vector< dimension > square_dimensions(vector< dimension > x, int index, long double &value)
Squares a vector of dimensions by an index. The value is updated too related to the prefix math and t...
vector< dimension > create_dimensions(string init_dimensions)
Creates the dimensions from an initialization string of dimensions.
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
vector< dimension > power_dimensions(const vector< dimension > &x, int exponent)
Powers the dimensions by an exponent.
bool operator<=(const scifir::scalar_unit &x, const scifir::scalar_unit &y)
Returns true if x has a lower or equal value than y, compared with the same dimensions....
istream & operator>>(istream &is, scifir::scalar_unit &x)
Allows that an istream initializes by string a scalar_unit x.
bool operator>(const scifir::scalar_unit &x, const scifir::scalar_unit &y)
Returns true if x has a greather value than y, compared with the same dimensions. If their dimensions...
string operator+(const string &x, const scifir::scalar_unit &y)
Creates a new string as the concatenation of the string x with the representation string of the scala...
bool operator!=(const scifir::scalar_unit &x, scifir::scalar_unit y)
Returns true if two scalar_unit classes doesn't have the same value when changed to same dimensions....
ostream & operator<<(ostream &os, const scifir::scalar_unit &x)
Adds the string representation of the scalar_unit x to an output stream os.
void operator+=(string &x, const scifir::scalar_unit &y)
Concatenates the string representation of the scalar_unit y to the string x.
bool operator==(const scifir::scalar_unit &x, const string &init_scalar)
Returns true if x is equal to the scalar_unit initialized with the string being compared....
bool operator<(const scifir::scalar_unit &x, const scifir::scalar_unit &y)
Returns true if x has a lower value than y, compared with the same dimensions. If their dimensions ar...
bool operator>=(const scifir::scalar_unit &x, const scifir::scalar_unit &y)
Returns true if x has a greather or equal value than y, compared with the same dimensions....