|
jaulib v1.4.0-2-g788cf73
Jau Support Library (C++, Java, ..)
|
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<typename 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<typename 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<typename 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<typename int_type> | |
| constexpr bool | jau::operator!= (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename 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<typename int_type> | |
| constexpr bool | jau::operator< (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<typename int_type> | |
| constexpr bool | jau::operator<= (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<typename int_type> | |
| constexpr bool | jau::operator== (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<typename int_type> | |
| constexpr bool | jau::operator> (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<typename int_type> | |
| constexpr bool | jau::operator>= (const fraction< int_type > &lhs, const fraction< int_type > &rhs) noexcept |
| template<typename 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 (const std::string &value, const fraction_i64 &min_allowed, const fraction_i64 &max_allowed) noexcept |
Returns the fraction_i64 of the given string in format <num>/<denom>, which may contain whitespace. | |
| template<typename 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().
| typedef fraction<int64_t> jau::fraction_i64 |
fraction using int64_t as integral type
Definition at line 737 of file fraction_type.hpp.
| typedef fraction<uint64_t> jau::fraction_u64 |
fraction using uint64_t as integral type
Definition at line 769 of file fraction_type.hpp.
| typedef ordered_atomic<jau::fraction_i64, std::memory_order_seq_cst> jau::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 1306 of file fraction_type.hpp.
| typedef ordered_atomic<jau::fraction_i64, std::memory_order_relaxed> jau::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 1309 of file fraction_type.hpp.
| typedef ordered_atomic<jau::fraction_u64, std::memory_order_seq_cst> jau::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 1312 of file fraction_type.hpp.
| typedef ordered_atomic<jau::fraction_u64, std::memory_order_relaxed> jau::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 1315 of file fraction_type.hpp.
|
noexcept |
Returns current monotonic time since Unix Epoch 00:00:00 UTC on 1970-01-01.
See http://man7.org/linux/man-pages/man2/clock_gettime.2.html
Returned fraction_timespec is passing machine precision and range of the underlying API.
See fraction_timespec::to_fraction_i64() of how to measure duration in high range and precision:
fraction_timespec t0 = getMonotonicTime(); // do something // Exact duration fraction_timespec td_1 = getMonotonicTime() - t0; // or for durations <= 292 years fraction_i64 td_2 = (getMonotonicTime() - t0).to_fraction_i64();
This is in stark contract to counting nanoseconds in int64_t which only lasts until 2262-04-12, since INT64_MAX is 9'223'372'036'854'775'807 for 9'223'372'036 seconds or 292 years.
Monotonic time shall be used for high-performance measurements of durations, since the underlying OS shall support fast calls.
Regarding avoiding kernel via VDSO, see http://man7.org/linux/man-pages/man7/vdso.7.html, clock_gettime seems to be well supported at least on kernel >= 4.4. Only bfin and sh are missing, while ia64 seems to be complicated.
Definition at line 66 of file basic_types.cpp.
|
noexcept |
Returns current wall-clock real-time since Unix Epoch 00:00:00 UTC on 1970-01-01.
Returned fraction_timespec is passing machine precision and range of the underlying API.
Wall-Clock time shall be used for accurate measurements of the actual time only, since the underlying OS unlikely supports fast calls.
Definition at line 72 of file basic_types.cpp.
|
inlinenoexcept |
Definition at line 547 of file fraction_type.hpp.
|
constexprnoexcept |
Definition at line 550 of file fraction_type.hpp.
|
constexprnoexcept |
Definition at line 555 of file fraction_type.hpp.
|
constexprnoexcept |
Definition at line 560 of file fraction_type.hpp.
|
constexprnoexcept |
Definition at line 565 of file fraction_type.hpp.
|
constexprnoexcept |
Definition at line 570 of file fraction_type.hpp.
|
constexprnoexcept |
Definition at line 575 of file fraction_type.hpp.
|
constexprnoexcept |
Return the maximum of the two given fractions.
Definition at line 581 of file fraction_type.hpp.
|
constexprnoexcept |
Return the minimum of the two given fractions.
Definition at line 587 of file fraction_type.hpp.
|
constexprnoexcept |
Returns the value of the sign function applied to numerator.
-1 for numerator < 0 0 for numerator = 0 1 for numerator > 0
Definition at line 601 of file fraction_type.hpp.
|
constexprnoexcept |
Returns the absolute fraction.
Definition at line 609 of file fraction_type.hpp.
|
constexprnoexcept |
Returns multiplication of fraction with scalar.
Operation may set the overflow flag in the returned instance, if occurring.
| int_type | integral type |
| lhs | the fraction |
| rhs | the scalar |
Definition at line 626 of file fraction_type.hpp.
|
constexprnoexcept |
Returns multiplication of fraction with scalar.
Operation may set the overflow flag in the returned instance, if occurring.
| int_type | integral type |
| lhs | the scalar |
| rhs | the fraction |
Definition at line 641 of file fraction_type.hpp.
|
constexprnoexcept |
Returns division of fraction with scalar.
| int_type | integral type |
| lhs | the fraction |
| rhs | the scalar |
Definition at line 653 of file fraction_type.hpp.
|
constexprnoexcept |
Returns division of fraction with scalar.
| int_type | integral type |
| lhs | the scalar |
| rhs | the fraction |
Definition at line 666 of file fraction_type.hpp.
|
constexprnoexcept |
Returns sum of two fraction.
Operation may set the overflow flag in the returned instance, if occurring.
| int_type | integral type |
| lhs | a fraction |
| rhs | a fraction |
Definition at line 682 of file fraction_type.hpp.
|
constexprnoexcept |
Returns difference of two fraction.
Operation may set the overflow flag in the returned instance, if occurring.
| int_type | integral type |
| lhs | a fraction |
| rhs | a fraction |
Definition at line 699 of file fraction_type.hpp.
|
constexprnoexcept |
Returns product of two fraction.
Operation may set the overflow flag in the returned instance, if occurring.
| int_type | integral type |
| lhs | a fraction |
| rhs | a fraction |
Definition at line 716 of file fraction_type.hpp.
|
constexprnoexcept |
Returns division of two fraction.
| int_type | integral type |
| lhs | a fraction |
| rhs | a fraction |
Definition at line 730 of file fraction_type.hpp.
|
noexcept |
Returns the fraction_i64 of the given string in format <num>/<denom>, which may contain whitespace.
It the given string value does not conform with the format or exceeds the given value range, complete=false is being returned.
If the given string 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.
| value | the string value |
| min_allowed | the minimum allowed value |
| max_allowed | the maximum allowed value |
Definition at line 960 of file basic_types.cpp.
|
inlinenoexcept |
Definition at line 1186 of file fraction_type.hpp.
|
constexprnoexcept |
Return the maximum of the two given fraction_timespec.
Definition at line 1189 of file fraction_type.hpp.
|
constexprnoexcept |
Return the minimum of the two given fraction_timespec.
Definition at line 1194 of file fraction_type.hpp.
|
constexprnoexcept |
Returns the value of the sign function applied to tv_sec.
-1 for numerator < 0 0 for numerator = 0 1 for numerator > 0
Definition at line 1207 of file fraction_type.hpp.
|
constexprnoexcept |
Returns the absolute fraction_timespec.
Definition at line 1214 of file fraction_type.hpp.
|
constexprnoexcept |
Returns sum of two fraction_timespec.
| lhs | a fraction_timespec |
| rhs | a fraction_timespec |
Definition at line 1228 of file fraction_type.hpp.
|
constexprnoexcept |
Returns difference of two fraction_timespec.
See fraction_timespec::to_fraction_i64().
| lhs | a fraction_timespec |
| rhs | a fraction_timespec |
Definition at line 1243 of file fraction_type.hpp.
|
constexprnoexcept |
Returns product of fraction_timespec * scalar.
| lhs | a fraction_timespec |
| rhs | a scalar |
Definition at line 1256 of file fraction_type.hpp.
|
constexprnoexcept |
Returns product of scalar * fraction_timespec.
| lhs | a scalar |
| rhs | a fraction_timespec |
Definition at line 1268 of file fraction_type.hpp.
|
constexprnoexcept |
Returns fraction of fraction_timespec / scalar.
| lhs | a fraction_timespec |
| rhs | a scalar |
Definition at line 1280 of file fraction_type.hpp.
|
constexprnoexcept |
Returns fraction of scalar / fraction_timespec.
| lhs | a scalar |
| rhs | a fraction_timespec |
Definition at line 1292 of file fraction_type.hpp.