quantity
namespace nin::inline units {
template <dimension D, std::floating_point T = double>
class quantity;
}
A physical quantity with a magnitude and a dimension. The magnitude is always stored internally in SI units, regardless of how the quantity was created.
Template parameters
-
D— Adimensionspecifying the physical dimension -
T— Astd::floating_pointtype for the magnitude (default:double)
Member functions
(Constructor)
constructs a quantity
(Constructor)
constructs a quantity
|
(1) |
|
(2) |
-
(1) Default constructor. Magnitude is zero.
-
(2) Converting constructor from a quantity with the same dimension but different floating-point type. Explicit if the conversion is narrowing.
operator <⇒
operator ==
comparison operators
operator <⇒
operator ==
comparison operators
|
(1) |
|
(2) |
-
(1) Equality comparison (cross-type).
-
(2) Three-way comparison. Generates
<,⇐,>,>=.
operator +=
operator -=
addition and subtraction assignment
operator +=
operator -=
addition and subtraction assignment
|
(1) |
|
(2) |
Adds or subtracts rhs from *this. The operands must have the same dimension.
operator *
operator /
multiplication and division with other quantities
operator *
operator /
multiplication and division with other quantities
|
(1) |
|
(2) |
-
(1) Returns a quantity whose dimension is the product of the two dimensions.
-
(2) Returns a quantity whose dimension is the quotient of the two dimensions.
There are no *= or /= operators for quantities with different dimensions,
since the result type differs from *this.
|
operator *=
operator /=
scalar multiplication and division assignment
operator *=
operator /=
scalar multiplication and division assignment
|
(1) |
|
(2) |
Multiplies or divides the magnitude by a scalar. Dimension is unchanged.
SI
magnitude in SI units
SI
magnitude in SI units
|
(1) |
Returns the magnitude in the International System of Units.
CGS
magnitude in CGS units
CGS
magnitude in CGS units
|
(1) |
Returns the magnitude in the centimetre-gram-second system.
in
magnitude in a given unit
in
magnitude in a given unit
|
(1) |
Returns the magnitude expressed in target_unit.
The target must have the same dimension.
auto d = 1_km;
d.in(1_mi); // ≈ 0.6214
degK
degC
degF
temperature conversions
degK
degC
degF
temperature conversions
|
(1) |
|
(2) |
|
(3) |
Available only for quantities with temperature dimension.
-
(1) Returns the temperature in kelvin (same as
SI()). -
(2) Returns the temperature in degrees Celsius.
-
(3) Returns the temperature in degrees Fahrenheit.
operator T
implicit conversion to scalar
operator T
implicit conversion to scalar
|
(1) |
Available only for dimensionless quantities. Returns the magnitude as a scalar.
operator std::chrono::duration
conversion to chrono duration
operator std::chrono::duration
conversion to chrono duration
|
(1) |
Available only for time quantities. Enables interoperability with <chrono>.
Non-member functions
operator +
operator -
unary operators
operator +
operator -
unary operators
|
(1) |
|
(2) |
-
(1) Returns
rhsunchanged. -
(2) Returns
rhswith negated magnitude.
operator +
operator -
binary addition and subtraction
operator +
operator -
binary addition and subtraction
|
(1) |
|
(2) |
Adds or subtracts two quantities of the same dimension.
operator *
operator /
scalar multiplication and division
operator *
operator /
scalar multiplication and division
|
(1) |
|
(2) |
|
(3) |
|
(4) |
-
(1)-(3) Scale the quantity by a scalar. Dimension unchanged.
-
(4) Dividing a scalar by a quantity inverts the dimension.
abs
fabs
absolute value
abs
fabs
absolute value
|
(1) |
|
(2) |
Returns the absolute value. Dimension unchanged.
sqrt
square root
sqrt
square root
|
(1) |
Returns the square root of the quantity. Halves each dimension exponent. Only available when all exponents are even.
hypot
hypotenuse / norm
hypot
hypotenuse / norm
|
(1) |
|
(2) |
-
(1) Returns \(\sqrt{v_1^2 + v_2^2}\).
-
(2) Returns \(\sqrt{v_1^2 + v_2^2 + v_3^2}\).
asin
acos
atan
atan2
inverse trigonometric functions
asin
acos
atan
atan2
inverse trigonometric functions
|
(1) |
|
(2) |
|
(3) |
|
(4) |
|
(5) |
-
(1)-(3) Take a scalar and return an angle.
-
(4) Takes a dimensionless quantity and returns an angle.
-
(5) Takes two quantities of the same dimension and returns an angle.