qtty-cpp 0.4.5
Header-only C++ wrapper for qtty
Loading...
Searching...
No Matches
qtty::Quantity< UnitTag > Class Template Reference

#include <qtty/ffi_core.hpp>

Public Types

using unit_tag = UnitTag

Public Member Functions

constexpr Quantity ()
constexpr Quantity (double value)
constexpr double value () const
constexpr const double & value_ref () const
constexpr double erase_unit_raw () const
template<typename TargetType>
Quantity< typename ExtractTag< TargetType >::type > to () const
Quantity operator+ (const Quantity &other) const
Quantity operator- (const Quantity &other) const
Quantity operator* (double scalar) const
Quantity operator/ (double scalar) const
bool operator== (const Quantity &other) const
bool operator!= (const Quantity &other) const
bool operator< (const Quantity &other) const
bool operator> (const Quantity &other) const
bool operator<= (const Quantity &other) const
bool operator>= (const Quantity &other) const
Quantity & operator+= (const Quantity &other)
Quantity & operator-= (const Quantity &other)
Quantity & operator*= (double scalar)
Quantity & operator/= (double scalar)
Quantity operator- () const
Quantity abs () const
Quantity min (const Quantity &other) const
Quantity max (const Quantity &other) const
Quantity clamp (const Quantity &min_val, const Quantity &max_val) const
Quantity mean (const Quantity &other) const
bool is_nan () const
bool is_infinite () const
bool is_finite () const
double signum () const
double scalar_sqrt () const
Quantity floor () const
Quantity ceil () const
Quantity round () const
Quantity trunc () const
Quantity fract () const
Quantity rem_euclid (double rhs) const
template<typename V>
bool eq_unit (const Quantity< V > &other) const
template<typename V>
std::optional< int > cmp_unit (const Quantity< V > &other) const
std::string format (int precision=-1, uint32_t flags=QTTY_FMT_DEFAULT) const
 Format this quantity as a string.

Static Public Member Functions

static constexpr UnitId unit_id ()
static constexpr Quantity zero ()
static constexpr Quantity one ()
static Quantity nan ()
static Quantity infinity ()
static Quantity neg_infinity ()

Friends

Quantity operator* (double scalar, const Quantity &q)

Detailed Description

template<typename UnitTag>
class qtty::Quantity< UnitTag >

Definition at line 178 of file ffi_core.hpp.

Member Typedef Documentation

◆ unit_tag

template<typename UnitTag>
using qtty::Quantity< UnitTag >::unit_tag = UnitTag

Definition at line 183 of file ffi_core.hpp.

Constructor & Destructor Documentation

◆ Quantity() [1/2]

template<typename UnitTag>
qtty::Quantity< UnitTag >::Quantity ( )
inlineconstexpr

Definition at line 186 of file ffi_core.hpp.

Referenced by qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::abs(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::ceil(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::clamp(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::floor(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::fract(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::infinity(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::max(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::mean(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::min(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::nan(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::neg_infinity(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::one(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::operator*(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::operator+(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::operator-(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::operator-(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::operator/(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::rem_euclid(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::round(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::to(), qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::trunc(), and qtty::Quantity< CompoundTag< KilometerTag, SecondTag > >::zero().

◆ Quantity() [2/2]

template<typename UnitTag>
qtty::Quantity< UnitTag >::Quantity ( double value)
inlineexplicitconstexpr

Definition at line 187 of file ffi_core.hpp.

Member Function Documentation

◆ abs()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::abs ( ) const
inline

Definition at line 342 of file ffi_core.hpp.

◆ ceil()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::ceil ( ) const
inline

Definition at line 380 of file ffi_core.hpp.

◆ clamp()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::clamp ( const Quantity< UnitTag > & min_val,
const Quantity< UnitTag > & max_val ) const
inline

Definition at line 352 of file ffi_core.hpp.

◆ cmp_unit()

template<typename UnitTag>
template<typename V>
std::optional< int > qtty::Quantity< UnitTag >::cmp_unit ( const Quantity< V > & other) const
inline

Definition at line 408 of file ffi_core.hpp.

◆ eq_unit()

template<typename UnitTag>
template<typename V>
bool qtty::Quantity< UnitTag >::eq_unit ( const Quantity< V > & other) const
inline

Definition at line 402 of file ffi_core.hpp.

◆ erase_unit_raw()

template<typename UnitTag>
double qtty::Quantity< UnitTag >::erase_unit_raw ( ) const
inlineconstexpr

Definition at line 201 of file ffi_core.hpp.

◆ floor()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::floor ( ) const
inline

Definition at line 379 of file ffi_core.hpp.

◆ format()

template<typename UnitTag>
std::string qtty::Quantity< UnitTag >::format ( int precision = -1,
uint32_t flags = QTTY_FMT_DEFAULT ) const
inline

Format this quantity as a string.

Delegates to the Rust qtty-ffi qtty_quantity_format function so that C++ and Rust produce identical output for the same parameters.

Parameters
precisionDigits after the decimal point. Pass a negative value (default) for the shortest exact representation.
flagsNotation selector:
  • QTTY_FMT_DEFAULT (0): decimal (e.g. "1234.57 m")
  • QTTY_FMT_LOWER_EXP (1): scientific lower-case e
  • QTTY_FMT_UPPER_EXP (2): scientific upper-case E
Returns
Formatted string, e.g. "1234.57 m" or "1.23e3 m".
Exceptions
QttyExceptionon formatting failure.

Definition at line 454 of file ffi_core.hpp.

◆ fract()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::fract ( ) const
inline

Definition at line 383 of file ffi_core.hpp.

◆ infinity()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::infinity ( )
inlinestatic

Definition at line 213 of file ffi_core.hpp.

◆ is_finite()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::is_finite ( ) const
inline

Definition at line 365 of file ffi_core.hpp.

◆ is_infinite()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::is_infinite ( ) const
inline

Definition at line 364 of file ffi_core.hpp.

◆ is_nan()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::is_nan ( ) const
inline

Definition at line 363 of file ffi_core.hpp.

◆ max()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::max ( const Quantity< UnitTag > & other) const
inline

Definition at line 350 of file ffi_core.hpp.

◆ mean()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::mean ( const Quantity< UnitTag > & other) const
inline

Definition at line 357 of file ffi_core.hpp.

◆ min()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::min ( const Quantity< UnitTag > & other) const
inline

Definition at line 348 of file ffi_core.hpp.

◆ nan()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::nan ( )
inlinestatic

Definition at line 212 of file ffi_core.hpp.

◆ neg_infinity()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::neg_infinity ( )
inlinestatic

Definition at line 214 of file ffi_core.hpp.

◆ one()

template<typename UnitTag>
constexpr Quantity qtty::Quantity< UnitTag >::one ( )
inlinestaticconstexpr

Definition at line 209 of file ffi_core.hpp.

◆ operator!=()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::operator!= ( const Quantity< UnitTag > & other) const
inline

Definition at line 299 of file ffi_core.hpp.

◆ operator*()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::operator* ( double scalar) const
inline

Definition at line 282 of file ffi_core.hpp.

◆ operator*=()

template<typename UnitTag>
Quantity & qtty::Quantity< UnitTag >::operator*= ( double scalar)
inline

Definition at line 325 of file ffi_core.hpp.

◆ operator+()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::operator+ ( const Quantity< UnitTag > & other) const
inline

Definition at line 271 of file ffi_core.hpp.

◆ operator+=()

template<typename UnitTag>
Quantity & qtty::Quantity< UnitTag >::operator+= ( const Quantity< UnitTag > & other)
inline

Definition at line 315 of file ffi_core.hpp.

◆ operator-() [1/2]

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::operator- ( ) const
inline

Definition at line 340 of file ffi_core.hpp.

◆ operator-() [2/2]

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::operator- ( const Quantity< UnitTag > & other) const
inline

Definition at line 273 of file ffi_core.hpp.

◆ operator-=()

template<typename UnitTag>
Quantity & qtty::Quantity< UnitTag >::operator-= ( const Quantity< UnitTag > & other)
inline

Definition at line 320 of file ffi_core.hpp.

◆ operator/()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::operator/ ( double scalar) const
inline

Definition at line 284 of file ffi_core.hpp.

◆ operator/=()

template<typename UnitTag>
Quantity & qtty::Quantity< UnitTag >::operator/= ( double scalar)
inline

Definition at line 330 of file ffi_core.hpp.

◆ operator<()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::operator< ( const Quantity< UnitTag > & other) const
inline

Definition at line 301 of file ffi_core.hpp.

◆ operator<=()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::operator<= ( const Quantity< UnitTag > & other) const
inline

Definition at line 305 of file ffi_core.hpp.

◆ operator==()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::operator== ( const Quantity< UnitTag > & other) const
inline

Definition at line 297 of file ffi_core.hpp.

◆ operator>()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::operator> ( const Quantity< UnitTag > & other) const
inline

Definition at line 303 of file ffi_core.hpp.

◆ operator>=()

template<typename UnitTag>
bool qtty::Quantity< UnitTag >::operator>= ( const Quantity< UnitTag > & other) const
inline

Definition at line 307 of file ffi_core.hpp.

◆ rem_euclid()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::rem_euclid ( double rhs) const
inline

Definition at line 386 of file ffi_core.hpp.

◆ round()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::round ( ) const
inline

Definition at line 381 of file ffi_core.hpp.

◆ scalar_sqrt()

template<typename UnitTag>
double qtty::Quantity< UnitTag >::scalar_sqrt ( ) const
inline

Definition at line 376 of file ffi_core.hpp.

◆ signum()

template<typename UnitTag>
double qtty::Quantity< UnitTag >::signum ( ) const
inline

Definition at line 372 of file ffi_core.hpp.

◆ to()

template<typename UnitTag>
template<typename TargetType>
Quantity< typename ExtractTag< TargetType >::type > qtty::Quantity< UnitTag >::to ( ) const
inline

◆ trunc()

template<typename UnitTag>
Quantity qtty::Quantity< UnitTag >::trunc ( ) const
inline

Definition at line 382 of file ffi_core.hpp.

◆ unit_id()

template<typename UnitTag>
constexpr UnitId qtty::Quantity< UnitTag >::unit_id ( )
inlinestaticconstexpr

◆ value()

◆ value_ref()

template<typename UnitTag>
const double & qtty::Quantity< UnitTag >::value_ref ( ) const
inlineconstexpr

Definition at line 196 of file ffi_core.hpp.

◆ zero()

template<typename UnitTag>
constexpr Quantity qtty::Quantity< UnitTag >::zero ( )
inlinestaticconstexpr

Definition at line 208 of file ffi_core.hpp.

◆ operator*

template<typename UnitTag>
Quantity operator* ( double scalar,
const Quantity< UnitTag > & q )
friend

Definition at line 287 of file ffi_core.hpp.


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