Gamp: Fraction Arithmetic and Time (original) (raw)
Fraction type and arithmetic support inclusive its utilization for time without loss of precision nor range. More...
| Namespaces | |
|---|---|
| namespace | jau::fraction_tv |
| namespace | jau::fractions_i64 |
| fractions namespace to provide fraction constants using int64_t as underlying integral integer type. | |
| namespace | jau::fractions_i64_literals |
| Classes | |
|---|---|
| struct | jau::FracI64SizeBoolTuple |
| Simple pre-defined value pair [fraction_i64, size_t, bool] for structured bindings to multi-values. More... | |
| class | jau::fraction< Int_type > |
| Fraction template type using integral values, evaluated at runtime. More... | |
| struct | jau::fraction_timespec |
| Timespec structure using int64_t for its components in analogy to struct timespec_t on 64-bit platforms. More... | |
| Typedefs | |
|---|---|
| typedef fraction< int64_t > | jau::fraction_i64 |
| fraction using int64_t as integral type | |
| typedef fraction< uint64_t > | jau::fraction_u64 |
| fraction using uint64_t as integral type | |
| typedef ordered_atomic< jau::fraction_i64, std::memory_order_relaxed > | jau::relaxed_atomic_fraction_i64 |
| Relaxed non-SC atomic integral scalar jau::fraction_i64. | |
| typedef ordered_atomic< jau::fraction_u64, std::memory_order_relaxed > | jau::relaxed_atomic_fraction_u64 |
| Relaxed non-SC atomic integral scalar jau::fraction_u64. | |
| typedef ordered_atomic< jau::fraction_i64, std::memory_order_seq_cst > | jau::sc_atomic_fraction_i64 |
| SC atomic integral scalar jau::fraction_i64. | |
| typedef ordered_atomic< jau::fraction_u64, std::memory_order_seq_cst > | jau::sc_atomic_fraction_u64 |
| SC atomic integral scalar jau::fraction_u64. | |
| Functions | |
|---|---|
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::abs (const fraction< int_type > &rhs) noexcept |
| Returns the absolute fraction. | |
| constexpr fraction_timespec | jau::abs (const fraction_timespec &rhs) noexcept |
| Returns the absolute fraction_timespec. | |
| fraction_timespec | jau::getMonotonicTime () noexcept |
| Returns current monotonic time since Unix Epoch 00:00:00 UTC on 1970-01-01. | |
| fraction_timespec | jau::getWallClockTime () noexcept |
| Returns current wall-clock real-time since Unix Epoch 00:00:00 UTC on 1970-01-01. | |
| template<std::integral int_type> | |
| constexpr const fraction< int_type > & | jau::max (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| Return the maximum of the two given fractions. | |
| constexpr const fraction_timespec & | jau::max (const fraction_timespec &lhs, const fraction_timespec &rhs) noexcept |
| Return the maximum of the two given fraction_timespec. | |
| template<std::integral int_type> | |
| constexpr const fraction< int_type > & | jau::max (fraction< int_type > &&, fraction< int_type > &&) noexcept=delete |
| constexpr const fraction_timespec & | jau::max (fraction_timespec &&, fraction_timespec &&) noexcept=delete |
| template<std::integral int_type> | |
| constexpr const fraction< int_type > & | jau::min (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| Return the minimum of the two given fractions. | |
| constexpr const fraction_timespec & | jau::min (const fraction_timespec &lhs, const fraction_timespec &rhs) noexcept |
| Return the minimum of the two given fraction_timespec. | |
| template<std::integral int_type> | |
| constexpr const fraction< int_type > & | jau::min (fraction< int_type > &&, fraction< int_type > &&) noexcept=delete |
| constexpr const fraction_timespec & | jau::min (fraction_timespec &&, fraction_timespec &&) noexcept=delete |
| template<std::integral int_type> | |
| constexpr bool | jau::operator!= (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::operator* (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| Returns product of two fraction. | |
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::operator* (const fraction< int_type > &lhs, const int_type &rhs) noexcept |
| Returns multiplication of fraction with scalar. | |
| constexpr fraction_timespec | jau::operator* (const fraction_timespec &lhs, const int64_t rhs) noexcept |
| Returns product of fraction_timespec * scalar. | |
| constexpr fraction_timespec | jau::operator* (const int64_t lhs, const fraction_timespec &rhs) noexcept |
| Returns product of scalar * fraction_timespec. | |
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::operator* (const int_type &lhs, const fraction< int_type > &rhs) noexcept |
| Returns multiplication of fraction with scalar. | |
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::operator+ (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| Returns sum of two fraction. | |
| constexpr fraction_timespec | jau::operator+ (const fraction_timespec &lhs, const fraction_timespec &rhs) noexcept |
| Returns sum of two fraction_timespec. | |
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::operator- (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| Returns difference of two fraction. | |
| constexpr fraction_timespec | jau::operator- (const fraction_timespec &lhs, const fraction_timespec &rhs) noexcept |
| Returns difference of two fraction_timespec. | |
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::operator/ (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| Returns division of two fraction. | |
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::operator/ (const fraction< int_type > &lhs, const int_type &rhs) noexcept |
| Returns division of fraction with scalar. | |
| constexpr fraction_timespec | jau::operator/ (const fraction_timespec &lhs, const int64_t rhs) noexcept |
| Returns fraction of fraction_timespec / scalar. | |
| constexpr fraction_timespec | jau::operator/ (const int64_t lhs, const fraction_timespec &rhs) noexcept |
| Returns fraction of scalar / fraction_timespec. | |
| template<std::integral int_type> | |
| constexpr fraction< int_type > | jau::operator/ (const int_type &lhs, const fraction< int_type > &rhs) noexcept |
| Returns division of fraction with scalar. | |
| template<std::integral int_type> | |
| constexpr bool | jau::operator< (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<std::integral int_type> | |
| constexpr bool | jau::operator<= (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<std::integral int_type> | |
| constexpr bool | jau::operator== (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<std::integral int_type> | |
| constexpr bool | jau::operator> (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<std::integral int_type> | |
| constexpr bool | jau::operator>= (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<std::integral int_type> | |
| constexpr snsize_t | jau::sign (const fraction< int_type > &rhs) noexcept |
| Returns the value of the sign function applied to numerator. | |
| constexpr snsize_t | jau::sign (const fraction_timespec &rhs) noexcept |
| Returns the value of the sign function applied to tv_sec. | |
| FracI64SizeBoolTuple | jau::to_fraction_i64 (std::string_view str, const fraction_i64 &min_allowed, const fraction_i64 &max_allowed) noexcept |
| Returns the fraction_i64 of the given character in format /, which may contain whitespace. | |
| template<std::integral int_type> | |
| std::string | jau::to_string (const fraction< int_type > &v) noexcept |
| std::string | jau::to_string (const fraction_timespec &v) noexcept |
Fraction type and arithmetic support inclusive its utilization for time without loss of precision nor range.
Adds support for Concurrency with general time functionality like sleep_until(), sleep_for(), wait_until() and wait_for(), completed with getMonotonicTime() and getWallClockTime().
◆ fraction_i64
◆ fraction_u64
◆ sc_atomic_fraction_i64
SC atomic integral scalar jau::fraction_i64.
Memory-Model (MM) guaranteed sequential consistency (SC) between acquire (read) and release (write). Requires libatomic with libstdc++10.
Definition at line 1311 of file fraction_type.hpp.
◆ relaxed_atomic_fraction_i64
Relaxed non-SC atomic integral scalar jau::fraction_i64.
Memory-Model (MM) only guarantees the atomic value, no sequential consistency (SC) between acquire (read) and release (write). Requires libatomic with libstdc++10.
Definition at line 1314 of file fraction_type.hpp.
◆ sc_atomic_fraction_u64
SC atomic integral scalar jau::fraction_u64.
Memory-Model (MM) guaranteed sequential consistency (SC) between acquire (read) and release (write). Requires libatomic with libstdc++10.
Definition at line 1317 of file fraction_type.hpp.
◆ relaxed_atomic_fraction_u64
Relaxed non-SC atomic integral scalar jau::fraction_u64.
Memory-Model (MM) only guarantees the atomic value, no sequential consistency (SC) between acquire (read) and release (write). Requires libatomic with libstdc++10.
Definition at line 1320 of file fraction_type.hpp.
◆ getMonotonicTime()
◆ getWallClockTime()
◆ to_string() [1/2]
template<std::integral int_type>
| std::string jau::to_string ( const fraction< int_type > & v) | inlinenoexcept |
|---|
◆ operator!=()
template<std::integral int_type>
◆ operator==()
template<std::integral int_type>
| bool jau::operator== ( const fraction< int_type > & lhs, const fraction< int_type > & rhs ) | constexprnoexcept |
|---|
◆ operator>()
template<std::integral int_type>
| bool jau::operator> ( const fraction< int_type > & lhs, const fraction< int_type > & rhs ) | constexprnoexcept |
|---|
◆ operator>=()
template<std::integral int_type>
| bool jau::operator>= ( const fraction< int_type > & lhs, const fraction< int_type > & rhs ) | constexprnoexcept |
|---|
◆ operator<()
template<std::integral int_type>
| bool jau::operator< ( const fraction< int_type > & lhs, const fraction< int_type > & rhs ) | constexprnoexcept |
|---|
◆ operator<=()
template<std::integral int_type>
| bool jau::operator<= ( const fraction< int_type > & lhs, const fraction< int_type > & rhs ) | constexprnoexcept |
|---|
◆ max() [1/4]
template<std::integral int_type>
◆ max() [2/4]
template<std::integral int_type>
◆ min() [1/4]
template<std::integral int_type>
◆ min() [2/4]
template<std::integral int_type>
◆ sign() [1/2]
template<std::integral int_type>
Returns the value of the sign function applied to numerator.
-1 for numerator < 0 0 for numerator = 0 1 for numerator > 0
Returns
function result
Definition at line 603 of file fraction_type.hpp.
◆ abs() [1/2]
template<std::integral int_type>
| fraction< int_type > jau::abs ( const fraction< int_type > & rhs) | constexprnoexcept |
|---|
◆ operator*() [1/5]
template<std::integral int_type>
| fraction< int_type > jau::operator* ( const fraction< int_type > & lhs, const int_type & rhs ) | constexprnoexcept |
|---|
Returns multiplication of fraction with scalar.
Operation may set the overflow flag in the returned instance, if occurring.
Template Parameters
Parameters
| lhs | the fraction |
|---|---|
| rhs | the scalar |
Returns
resulting new fraction, reduced
Definition at line 628 of file fraction_type.hpp.
◆ operator*() [2/5]
template<std::integral int_type>
| fraction< int_type > jau::operator* ( const int_type & lhs, const fraction< int_type > & rhs ) | constexprnoexcept |
|---|
Returns multiplication of fraction with scalar.
Operation may set the overflow flag in the returned instance, if occurring.
Template Parameters
Parameters
| lhs | the scalar |
|---|---|
| rhs | the fraction |
Returns
resulting new fraction, reduced
Definition at line 643 of file fraction_type.hpp.
◆ operator/() [1/5]
template<std::integral int_type>
| fraction< int_type > jau::operator/ ( const fraction< int_type > & lhs, const int_type & rhs ) | constexprnoexcept |
|---|
Returns division of fraction with scalar.
Template Parameters
Parameters
| lhs | the fraction |
|---|---|
| rhs | the scalar |
Returns
resulting new fraction, reduced
Definition at line 655 of file fraction_type.hpp.
◆ operator/() [2/5]
template<std::integral int_type>
| fraction< int_type > jau::operator/ ( const int_type & lhs, const fraction< int_type > & rhs ) | constexprnoexcept |
|---|
Returns division of fraction with scalar.
Template Parameters
Parameters
| lhs | the scalar |
|---|---|
| rhs | the fraction |
Returns
resulting new fraction, reduced
Definition at line 668 of file fraction_type.hpp.
◆ operator+() [1/2]
template<std::integral int_type>
Returns sum of two fraction.
Operation may set the overflow flag in the returned instance, if occurring.
Template Parameters
Parameters
| lhs | a fraction |
|---|---|
| rhs | a fraction |
Returns
resulting new fraction, reduced
Definition at line 684 of file fraction_type.hpp.
◆ operator-() [1/2]
template<std::integral int_type>
Returns difference of two fraction.
Operation may set the overflow flag in the returned instance, if occurring.
Template Parameters
Parameters
| lhs | a fraction |
|---|---|
| rhs | a fraction |
Returns
resulting new fraction, reduced
Definition at line 701 of file fraction_type.hpp.
◆ operator*() [3/5]
template<std::integral int_type>
Returns product of two fraction.
Operation may set the overflow flag in the returned instance, if occurring.
Template Parameters
Parameters
| lhs | a fraction |
|---|---|
| rhs | a fraction |
Returns
resulting new fraction, reduced
Definition at line 718 of file fraction_type.hpp.
◆ operator/() [3/5]
template<std::integral int_type>
Returns division of two fraction.
Template Parameters
Parameters
| lhs | a fraction |
|---|---|
| rhs | a fraction |
Returns
resulting new fraction, reduced
Definition at line 732 of file fraction_type.hpp.
◆ to_fraction_i64()
| FracI64SizeBoolTuple jau::to_fraction_i64 ( std::string_view str, const fraction_i64 & min_allowed, const fraction_i64 & max_allowed ) | noexcept |
|---|
Returns the fraction_i64 of the given character in format <num>/<denom>, which may contain whitespace.
It the given character value does not conform with the format or exceeds the given value range, complete=false is being returned.
If the given character value has been accepted, it is stored in the result reference and complete=true is being returned.
You may use C++17 structured bindings to handle the tuple
[[fraction_i64](#gaf8ab010196c6db11da2bf45c9d39bc97 "fraction using int64_t as integral type") result, size_t consumed_chars, bool complete]
Parameters
| str | the character to parse |
|---|---|
| min_allowed | the minimum allowed value |
| max_allowed | the maximum allowed value |
Returns
tuple [fraction_i64 result, size_t consumed_chars, bool complete], i.e. complete is true if value has been accepted, otherwise false
Definition at line 1198 of file basic_types.cpp.
◆ to_string() [2/2]
◆ max() [3/4]
◆ max() [4/4]
◆ min() [3/4]
◆ min() [4/4]
◆ sign() [2/2]
Returns the value of the sign function applied to tv_sec.
-1 for numerator < 0 0 for numerator = 0 1 for numerator > 0
Returns
function result
Definition at line 1212 of file fraction_type.hpp.