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
scalar_unit.hpp
Go to the documentation of this file.
1#ifndef SCIFIR_UNITS_UNITS_SCALAR_UNIT_HPP_INCLUDED
2#define SCIFIR_UNITS_UNITS_SCALAR_UNIT_HPP_INCLUDED
3
4#include "./dimension.hpp"
5#include "./prefix.hpp"
6#include "../util/is_number.hpp"
7
8#include <cmath>
9#include <map>
10#include <string>
11#include <iostream>
12#include <sstream>
13#include <string_view>
14#include <vector>
15
16#define SCALAR_UNIT_HPP_BEGIN(name) class name : public scalar_unit \
17 { \
18 public: \
19 name(); \
20 name(const name&); \
21 name(name&&); \
22 explicit name(float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
23 explicit name(double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
24 explicit name(long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
25 explicit name(int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
26 explicit name(float new_value, const string& init_dimensions); \
27 explicit name(double new_value, const string& init_dimensions); \
28 explicit name(long double new_value, const string& init_dimensions); \
29 explicit name(int new_value, const string& init_dimensions); \
30 explicit name(float new_value, const vector<dimension>& new_dimensions); \
31 explicit name(double new_value, const vector<dimension>& new_dimensions); \
32 explicit name(long double new_value, const vector<dimension>& new_dimensions); \
33 explicit name(int new_value, const vector<dimension>& new_dimensions); \
34 explicit name(const string& init_scalar); \
35 explicit name(const scalar_unit&); \
36 explicit name(scalar_unit&&); \
37 name& operator =(const name&); \
38 name& operator =(name&&); \
39 using scalar_unit::operator =; \
40 using scalar_unit::operator +=; \
41 using scalar_unit::operator -=
42
43#define SCALAR_UNIT_HPP_END() \
44\
45 public: \
46 static const string dimensions_match; \
47 static const vector<dimension> real_dimensions; \
48 }
49
50#define SCALAR_UNIT_HPP(name) class name : public scalar_unit \
51 { \
52 public: \
53 name(); \
54 name(const name&); \
55 name(name&&); \
56 explicit name(float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
57 explicit name(double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
58 explicit name(long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
59 explicit name(int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position = dimension::NUMERATOR); \
60 explicit name(float new_value, const string& init_dimensions); \
61 explicit name(double new_value, const string& init_dimensions); \
62 explicit name(long double new_value, const string& init_dimensions); \
63 explicit name(int new_value, const string& init_dimensions); \
64 explicit name(float new_value, const vector<dimension>& new_dimensions); \
65 explicit name(double new_value, const vector<dimension>& new_dimensions); \
66 explicit name(long double new_value, const vector<dimension>& new_dimensions); \
67 explicit name(int new_value, const vector<dimension>& new_dimensions); \
68 explicit name(const string& init_scalar); \
69 explicit name(const scalar_unit&); \
70 explicit name(scalar_unit&&); \
71 name& operator =(const name&); \
72 name& operator =(name&&); \
73 using scalar_unit::operator =; \
74 using scalar_unit::operator +=; \
75 using scalar_unit::operator -=; \
76\
77 static const string dimensions_match; \
78 static const vector<dimension> real_dimensions; \
79 }
80
81#define SCALAR_UNIT_CPP(name,init_real_dimensions) name::name() : scalar_unit() { \
82 scalar_unit::dimensions = name::real_dimensions; \
83} \
84\
85 name::name(const name& x) : scalar_unit() \
86 { \
87 value = x.get_value(); \
88 dimensions = x.get_dimensions(); \
89 } \
90\
91 name::name(name&& x) : scalar_unit() \
92 { \
93 value = std::move(x.get_value()); \
94 dimensions = std::move(x.get_dimensions()); \
95 } \
96\
97 name::name(float new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position) : scalar_unit(new_value,new_dimension,new_prefix,new_position) \
98 { \
99 scalar_unit::check_dimensions(name::real_dimensions); \
100 } \
101\
102 name::name(double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position) : scalar_unit(new_value,new_dimension,new_prefix,new_position) \
103 { \
104 scalar_unit::check_dimensions(name::real_dimensions); \
105 } \
106\
107 name::name(long double new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position) : scalar_unit(new_value,new_dimension,new_prefix,new_position) \
108 { \
109 scalar_unit::check_dimensions(name::real_dimensions); \
110 } \
111\
112 name::name(int new_value, dimension::type new_dimension, prefix::type new_prefix, dimension::position new_position) : scalar_unit(new_value,new_dimension,new_prefix,new_position) \
113 { \
114 scalar_unit::check_dimensions(name::real_dimensions); \
115 } \
116\
117 name::name(float new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
118 { \
119 scalar_unit::check_dimensions(name::real_dimensions); \
120 } \
121\
122 name::name(double new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
123 { \
124 scalar_unit::check_dimensions(name::real_dimensions); \
125 } \
126\
127 name::name(long double new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
128 { \
129 scalar_unit::check_dimensions(name::real_dimensions); \
130 } \
131\
132 name::name(int new_value, const string& init_dimensions) : scalar_unit(new_value,init_dimensions) \
133 { \
134 scalar_unit::check_dimensions(name::real_dimensions); \
135 } \
136\
137 name::name(float new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
138 { \
139 scalar_unit::check_dimensions(name::real_dimensions); \
140 } \
141\
142 name::name(double new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
143 { \
144 scalar_unit::check_dimensions(name::real_dimensions); \
145 } \
146\
147 name::name(long double new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
148 { \
149 scalar_unit::check_dimensions(name::real_dimensions); \
150 } \
151\
152 name::name(int new_value, const vector<dimension>& new_dimensions) : scalar_unit(new_value,new_dimensions) \
153 { \
154 scalar_unit::check_dimensions(name::real_dimensions); \
155 } \
156\
157 name::name(const string& init_scalar) : scalar_unit() \
158 { \
159 initialize_from_string(init_scalar,name::real_dimensions); \
160 } \
161\
162 name::name(const scalar_unit& x) : scalar_unit() \
163 { \
164 if (x.has_dimensions(name::real_dimensions)) \
165 { \
166 value = x.get_value(); \
167 dimensions = x.get_dimensions(); \
168 } \
169 } \
170\
171 name::name(scalar_unit&& x) : scalar_unit() \
172 { \
173 if (x.has_dimensions(name::real_dimensions)) \
174 { \
175 value = std::move(x.get_value()); \
176 dimensions = std::move(x.get_dimensions()); \
177 } \
178 } \
179\
180 name& name::operator =(const name& x) \
181 { \
182 value = x.get_value(); \
183 dimensions = x.get_dimensions(); \
184 return *this; \
185 } \
186\
187 name& name::operator =(name&& x) \
188 { \
189 value = std::move(x.get_value()); \
190 dimensions = std::move(x.get_dimensions()); \
191 return *this; \
192 } \
193\
194const string name::dimensions_match = init_real_dimensions; \
195const vector<dimension> name::real_dimensions = create_base_dimensions(init_real_dimensions)
196
197using namespace std;
198
199namespace scifir
200{
202 {
203 public:
204 scalar_unit();
205 scalar_unit(const scalar_unit& x);
211 explicit scalar_unit(float new_value, const string& init_dimensions);
212 explicit scalar_unit(double new_value, const string& init_dimensions);
213 explicit scalar_unit(long double new_value, const string& init_dimensions);
214 explicit scalar_unit(int new_value, const string& init_dimensions);
216 explicit scalar_unit(double new_value, const vector<dimension>& new_dimensions);
217 explicit scalar_unit(long double new_value, const vector<dimension>& new_dimensions);
219 explicit scalar_unit(const string& init_scalar);
220
223 scalar_unit& operator =(const string& init_scalar);
224
225 explicit operator float() const;
226
227 bool operator ==(scalar_unit x) const;
228
233 scalar_unit operator ^(const scalar_unit& x) const;
234 void operator +=(scalar_unit x);
235 void operator -=(scalar_unit x);
236
239 {
240 scalar_unit x = *this;
241 x += y;
242 return x;
243 }
244
247 {
248 scalar_unit x = *this;
249 x -= y;
250 return x;
251 }
252
255 {
256 scalar_unit x = *this;
257 x *= y;
258 return x;
259 }
260
263 {
264 scalar_unit x = *this;
265 x /= y;
266 return x;
267 }
268
271 {
272 return scalar_unit(std::pow(get_value(),y),power_dimensions(get_dimensions(),y));
273 }
274
277 {
278 value += y;
279 }
280
283 {
284 value -= y;
285 }
286
289 {
290 value *= y;
291 }
292
295 {
296 value /= y;
297 }
298
303
304 void change_dimensions(const string& init_dimensions);
305 void change_dimensions(const scalar_unit& x);
306 bool has_dimensions(const string& init_dimensions) const;
308 bool has_dimensions(const scalar_unit& x) const;
309 bool has_empty_dimensions() const;
310 bool is_dimensionless() const;
311 bool has_simple_dimensions() const;
312 bool has_single_dimensions() const;
313 bool has_composite_dimensions() const;
314 string display_dimensions() const;
315
317
318 //string get_dimensions_match() const;
320
321 inline const vector<dimension>& get_dimensions() const
322 {
323 return dimensions;
324 }
325
326 inline const float& get_value() const
327 {
328 return value;
329 }
330
331 string display(int number_of_decimals = 2 ,bool with_brackets = false,bool use_close_prefix = false) const;
332 string base_display(int number_of_decimals = 2,bool with_brackets = false,bool use_close_prefix = false) const;
333 string custom_display(const string& init_dimensions,int number_of_decimals = 2,bool with_brackets = false) const;
334
335 string to_latex(const string& init_dimensions,int number_of_decimals = 2,bool with_brackets = false) const;
336
337 protected:
339 float value;
340
343 void initialize_from_string(string init_scalar,const vector<dimension>& real_dimensions);
344 void check_dimensions(const vector<dimension>& real_dimensions);
345 };
346
347 string to_string(const scalar_unit& x);
348 bool is_scalar_unit(const string& init_scalar);
349 float abs(const scalar_unit& x);
350 scalar_unit pow(const scalar_unit& x,int exponent);
351 scalar_unit sqrt(const scalar_unit& x);
352 scalar_unit sqrt_nth(const scalar_unit& x, int index);
353
354 /*constexpr bool is_valid_scalar_unit(const char* x_init)
355 {
356 string_view x = x_init;
357 bool dot_present = false;
358 bool e_present = false;
359 int current_pos = 0;
360 int e_present_pos = 0;
361 for (int i = 0; i < x.length(); i++)
362 {
363 if (x[i] == ' ')
364 {
365 if (e_present and ((e_present_pos + 1) == i))
366 {
367 return false;
368 }
369 current_pos = i;
370 break;
371 }
372 if (e_present == false)
373 {
374 if (x[i] == '.')
375 {
376 if (dot_present)
377 {
378 return false;
379 }
380 else
381 {
382 dot_present = true;
383 }
384 }
385 else if (x[i] == 'e' or x[i] == 'E')
386 {
387 e_present = true;
388 e_present_pos = i;
389 continue;
390 }
391 else if (x[i] == '*')
392 {
393 if (!(x.substr(i + 1,3) == "10^"))
394 {
395 return false;
396 }
397 else
398 {
399 e_present = true;
400 i += 3;
401 e_present_pos = i;
402 continue;
403 }
404 }
405 else if (!isdigit(x[i]))
406 {
407 return false;
408 }
409 else if (i == (x.length() - 1))
410 {
411 return false;
412 }
413 }
414 else
415 {
416 if (!isdigit(x[i]))
417 {
418 return false;
419 }
420 }
421 }
422 if (current_pos == (x.length() - 1))
423 {
424 return false;
425 }
426 if (current_pos == 0)
427 {
428 return false;
429 }
430 vector<string_view> values = x | std::ranges::split(x,"/") | std::ranges::to<std::vector>();
431// boost::split(values,x.substr(current_pos),boost::is_any_of("/"));
432 if (values.size() == 1)
433 {
434 vector<string_view> subvalues;
435 boost::split(subvalues,values[0],boost::is_any_of("*"));
436 for (string_view& x_subvalue : subvalues)
437 {
438 boost::trim(x_subvalue);
439 bool number_present = false;
440 for (int i = 0; i < x_subvalue.length(); i++)
441 {
442 if (number_present == false)
443 {
444 if (isdigit(x_subvalue[i]))
445 {
446 number_present = true;
447 continue;
448 }
449 else if (!isalpha(x_subvalue[i]))
450 {
451 return false;
452 }
453 }
454 else
455 {
456 if (!isdigit(x_subvalue[i]))
457 {
458 return false;
459 }
460 }
461 }
462 }
463 return true;
464 }
465 else if (values.size() == 2)
466 {
467 if (values[0] != "1")
468 {
469 vector<string_view> subvalues;
470 boost::split(subvalues,values[0],boost::is_any_of("*"));
471 for (string_view& x_subvalue : subvalues)
472 {
473 boost::trim(x_subvalue);
474 bool number_present = false;
475 for (int i = 0; i < x_subvalue.length(); i++)
476 {
477 if (number_present == false)
478 {
479 if (isdigit(x_subvalue[i]))
480 {
481 number_present = true;
482 continue;
483 }
484 else if (!isalpha(x_subvalue[i]))
485 {
486 return false;
487 }
488 }
489 else
490 {
491 if (!isdigit(x_subvalue[i]))
492 {
493 return false;
494 }
495 }
496 }
497 }
498 }
499 vector<string_view> subvalues_denominator;
500 boost::split(subvalues_denominator,values[1],boost::is_any_of("*"));
501 for (string_view& x_subvalue : subvalues_denominator)
502 {
503 boost::trim(x_subvalue);
504 bool number_present = false;
505 for (int i = 0; i < x_subvalue.length(); i++)
506 {
507 if (number_present == false)
508 {
509 if (isdigit(x_subvalue[i]))
510 {
511 number_present = true;
512 continue;
513 }
514 else if (!isalpha(x_subvalue[i]))
515 {
516 return false;
517 }
518 }
519 else
520 {
521 if (!isdigit(x_subvalue[i]))
522 {
523 return false;
524 }
525 }
526 }
527 }
528 return true;
529 }
530 return false;
531 }*/
532}
533
534template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
536{
538 z += y;
539 return z;
540}
541
542template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
544{
546 z -= x;
547 return z;
548}
549
550template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
552{
554 z *= y;
555 return z;
556}
557
558template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
560{
561 scifir::scalar_unit z = scifir::scalar_unit((long double)y,vector<scifir::dimension>());
562 return z / x;
563}
564
565template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
566float operator ^(const T& x, const scifir::scalar_unit& y)
567{
569 {
570 return std::pow(x, y.get_value());
571 }
572 else
573 {
574 return 0;
575 }
576}
577
579bool operator <(const scifir::scalar_unit& x, const scifir::scalar_unit& y);
580bool operator >(const scifir::scalar_unit& x, const scifir::scalar_unit& y);
583
584bool operator ==(const scifir::scalar_unit& x, const string& init_scalar);
585bool operator !=(const scifir::scalar_unit& x, const string& init_scalar);
586bool operator <(const scifir::scalar_unit& x, const string& init_scalar);
587bool operator >(const scifir::scalar_unit& x, const string& init_scalar);
588bool operator <=(const scifir::scalar_unit& x, const string& init_scalar);
589bool operator >=(const scifir::scalar_unit& x, const string& init_scalar);
590
591bool operator ==(const string& init_scalar, const scifir::scalar_unit& x);
592bool operator !=(const string& init_scalar, const scifir::scalar_unit& x);
593bool operator <(const string& init_scalar, const scifir::scalar_unit& x);
594bool operator >(const string& init_scalar, const scifir::scalar_unit& x);
595bool operator <=(const string& init_scalar, const scifir::scalar_unit& x);
596bool operator >=(const string& init_scalar, const scifir::scalar_unit& x);
597
598template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
599bool operator ==(const T& x, const scifir::scalar_unit& y)
600{
601 return (x == y.get_value());
602}
603
604template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
605bool operator !=(const T& x, const scifir::scalar_unit& y)
606{
607 return !(x == y);
608}
609
610template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
611bool operator <(const T& x, const scifir::scalar_unit& y)
612{
613 return (x < y.get_value());
614}
615
616template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
617bool operator >(const T& x, const scifir::scalar_unit& y)
618{
619 return (x > y.get_value());
620}
621
622template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
623bool operator <=(const T& x, const scifir::scalar_unit& y)
624{
625 return (x <= y.get_value());
626}
627
628template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
629bool operator >=(const T& x, const scifir::scalar_unit& y)
630{
631 return (x >= y.get_value());
632}
633
634template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
635bool operator ==(const scifir::scalar_unit& x, const T& y)
636{
637 return (x.get_value() == y);
638}
639
640template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
641bool operator !=(const scifir::scalar_unit& x, const T& y)
642{
643 return !(x == y);
644}
645
646template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
647bool operator <(const scifir::scalar_unit& x,const T& y)
648{
649 return (x.get_value() < y);
650}
651
652template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
653bool operator >(const scifir::scalar_unit& x,const T& y)
654{
655 return (x.get_value() > y);
656}
657
658template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
659bool operator <=(const scifir::scalar_unit& x,const T& y)
660{
661 return (x.get_value() <= y);
662}
663
664template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
665bool operator >=(const scifir::scalar_unit& x,const T& y)
666{
667 return (x.get_value() >= y);
668}
669
670void operator +=(string& x, const scifir::scalar_unit& y);
671string operator +(const string& x, const scifir::scalar_unit& y);
672string operator +(const scifir::scalar_unit& y, const string& x);
673
674ostream& operator <<(ostream& os, const scifir::scalar_unit& x);
675istream& operator >>(istream& is, scifir::scalar_unit& x);
676
677#endif // SCIFIR_UNITS_UNITS_SCALAR_UNIT_HPP_INCLUDED
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
Definition dimension.hpp:31
position
Represents the position of the dimension, which can be at the numerator or at the denominator....
Definition dimension.hpp:38
@ NUMERATOR
The dimension is at the numerator.
Definition dimension.hpp:38
type
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are su...
Definition dimension.hpp:34
type
Represents a prefix of the SI system of units. All the prefixes of the SI system of units are support...
Definition prefix.hpp:16
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.
void operator*=(T y)
Multiplication operator, it multiplies the numeric type to the value, independent of the 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/=(T y)
Division operator, it divides the numeric type to the value, independent of the dimensions.
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.
Definition address.cpp:6
angle sqrt_nth(const angle &x, int index)
Calculates the nth root of the angle x and returns that new angle.
Definition angle.cpp:421
T abs(const complex_number< T > &x)
bool is_scalar_unit(const string &init_scalar)
Checks if an string is an initialization string of a scalar_unit.
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.
Definition aid.cpp:582
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
Definition angle.cpp:416
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....
scifir::scalar_unit operator/(const T &y, const scifir::scalar_unit &x)
Divides a numeric type y with an scalar_unit x, returns that result as a new scalar_unit with the sam...
scifir::scalar_unit operator+(const T &y, const scifir::scalar_unit &x)
Sums a numeric type y with an scalar_unit x, returns that result as a new scalar_unit with the same d...
scifir::scalar_unit operator-(const T &y, const scifir::scalar_unit &x)
Substracts a scalar_unit x to a numeric type y, returns that result as a new scalar_unit with the sam...
scifir::scalar_unit operator*(const T &y, const scifir::scalar_unit &x)
Multiplies a numeric type y with an scalar_unit x, returns that result as a new scalar_unit with the ...
float operator^(const T &x, const scifir::scalar_unit &y)
Exponentiates a numeric type x with a scalar_unit y, only if that scalar_unit as empty 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...
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....