|
Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
|
Physical quantity with a value and a compile-time unit. More...
#include <Quantity.hpp>
Public Member Functions | |
| constexpr | Quantity (const double v=0.0) |
| Construct a quantity with a given value (default: 0) | |
| template<typename OtherUnit > | |
| constexpr | Quantity (Quantity< OtherUnit > other) |
| Convert from another unit of the same dimension. | |
| template<typename TargetUnit > | |
| constexpr auto | As () const |
| Convert this quantity to a different unit of the same dimension. | |
| template<typename TargetType > | |
| constexpr auto | To () const |
| Extract the numeric value as a different type. | |
| template<typename OtherUnit > | |
| constexpr Quantity & | operator+= (Quantity< OtherUnit > other) |
| Add another quantity of the same dimension. | |
| template<typename OtherUnit > | |
| constexpr Quantity & | operator-= (Quantity< OtherUnit > other) |
| Subtract another quantity of the same dimension. | |
| constexpr Quantity & | operator*= (const double scalar) |
| Multiply the value by a scalar. | |
| constexpr Quantity & | operator/= (const double scalar) |
| Divide the value by a scalar. | |
| constexpr Quantity & | operator++ () |
| Pre-increment: increase value by 1. | |
| constexpr Quantity & | operator-- () |
| Pre-decrement: decrease value by 1. | |
| constexpr Quantity | operator++ (int) |
| Post-increment: increase value by 1, return old value. | |
| constexpr Quantity | operator-- (int) |
| Post-decrement: decrease value by 1, return old value. | |
Public Attributes | |
| double | value |
Physical quantity with a value and a compile-time unit.
Quantity is the primary user-facing type. It stores a numeric value and carries a unit type that encodes both dimension (SI exponents) and scale (e.g., meter vs. kilometer).
| UnitT | A unit type (e.g., Unit<Length, std::ratio<1>>) |
Example: Quantity<Meter> length = 5.0_m; Quantity<Second> time = 3.0_s; auto speed = length / time; // Quantity<Velocity> with value ~1.666...
Definition at line 27 of file Quantity.hpp.
|
inlineconstexpr |
Construct a quantity with a given value (default: 0)
Definition at line 34 of file Quantity.hpp.
|
inlineconstexpr |
Convert from another unit of the same dimension.
The stored value is converted to this unit's scale.
| OtherUnit | The source unit type |
| other | The quantity to convert from |
Definition at line 46 of file Quantity.hpp.
|
inlineconstexpr |
Convert this quantity to a different unit of the same dimension.
| TargetUnit | The target unit type |
Example: auto length = 1.0_km; auto in_meters = length.as<Meter>(); // 1000 m
Definition at line 63 of file Quantity.hpp.
|
inlineconstexpr |
Multiply the value by a scalar.
Definition at line 112 of file Quantity.hpp.
|
inlineconstexpr |
Pre-increment: increase value by 1.
Definition at line 124 of file Quantity.hpp.
|
inlineconstexpr |
Post-increment: increase value by 1, return old value.
Definition at line 136 of file Quantity.hpp.
|
inlineconstexpr |
Add another quantity of the same dimension.
| OtherUnit | The other quantity's unit type |
| other | The quantity to add |
Definition at line 89 of file Quantity.hpp.
|
inlineconstexpr |
Pre-decrement: decrease value by 1.
Definition at line 130 of file Quantity.hpp.
|
inlineconstexpr |
Post-decrement: decrease value by 1, return old value.
Definition at line 143 of file Quantity.hpp.
|
inlineconstexpr |
Subtract another quantity of the same dimension.
| OtherUnit | The other quantity's unit type |
| other | The quantity to subtract |
Definition at line 104 of file Quantity.hpp.
|
inlineconstexpr |
Divide the value by a scalar.
Definition at line 118 of file Quantity.hpp.
|
inlineconstexpr |
Extract the numeric value as a different type.
| TargetType | The numeric type to convert to (e.g., float, int) |
Definition at line 77 of file Quantity.hpp.
| double Phyth::Quantity< UnitT >::value |
The numeric value of this quantity, stored in the unit's base scale
Definition at line 31 of file Quantity.hpp.