|
frequency 1.2.0
Type-safe frequency handling library modeled after std::chrono
|
#include <cmath>#include <compare>#include <concepts>#include <cstdint>#include <limits>#include <ratio>#include <string>#include <assert.h>Go to the source code of this file.
Classes | |
| struct | freq::is_frequency< T > |
| Trait to detect frequency specializations. More... | |
| struct | freq::is_frequency< frequency< Rep, Precision > > |
| class | freq::frequency< Rep, Precision > |
| A frequency value with a representation and precision. More... | |
Namespaces | |
| namespace | freq |
| Frequency types and utilities. | |
| namespace | std |
| namespace | frequency_literals |
| User-defined literals for frequency types. | |
Macros | |
| #define | CONFIG_FREQUENCY_STD_FORMAT 0 |
Typedefs | |
| using | freq::millihertz = frequency< int64_t, std::milli > |
| Frequency with 0.001 Hz (millihertz) precision. | |
| using | freq::hertz = frequency< int64_t > |
| Frequency with 1 Hz precision. | |
| using | freq::kilohertz = frequency< int64_t, std::kilo > |
| Frequency with 1000 Hz (kilohertz) precision. | |
| using | freq::megahertz = frequency< int64_t, std::mega > |
| Frequency with 1,000,000 Hz (megahertz) precision. | |
| using | freq::gigahertz = frequency< int64_t, std::giga > |
| Frequency with 1,000,000,000 Hz (gigahertz) precision. | |
| using | freq::terahertz = frequency< int64_t, std::tera > |
| Frequency with 1,000,000,000,000 Hz (terahertz) precision. | |
Functions | |
| template<typename ToFreq , typename Rep , typename Precision > | |
| constexpr ToFreq | freq::frequency_cast (const frequency< Rep, Precision > &f) |
| Converts a frequency to a different precision or representation. | |
| template<typename ToFreq , typename Rep , typename Precision > | |
| constexpr ToFreq | freq::floor (const frequency< Rep, Precision > &f) |
| Converts a frequency to the target type, rounding toward negative infinity. | |
| template<typename ToFreq , typename Rep , typename Precision > | |
| constexpr ToFreq | freq::ceil (const frequency< Rep, Precision > &f) |
| Converts a frequency to the target type, rounding toward positive infinity. | |
| template<typename ToFreq , typename Rep , typename Precision > | |
| constexpr ToFreq | freq::round (const frequency< Rep, Precision > &f) |
| Converts a frequency to the target type, rounding to nearest (ties to even). | |
| template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 > | |
| constexpr auto | freq::beat (const frequency< Rep1, Precision1 > &f1, const frequency< Rep2, Precision2 > &f2) -> std::common_type_t< frequency< Rep1, Precision1 >, frequency< Rep2, Precision2 > > |
| Calculates the beat frequency between two frequencies. | |
| template<typename Rep , typename Precision > | |
| constexpr frequency< Rep, Precision > | freq::abs (const frequency< Rep, Precision > &f) |
| Returns the absolute value of a frequency. | |
| template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 > | |
| constexpr auto | freq::operator+ (const frequency< Rep1, Precision1 > &lhs, const frequency< Rep2, Precision2 > &rhs) -> std::common_type_t< frequency< Rep1, Precision1 >, frequency< Rep2, Precision2 > > |
| Returns the sum of two frequencies. | |
| template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 > | |
| constexpr auto | freq::operator- (const frequency< Rep1, Precision1 > &lhs, const frequency< Rep2, Precision2 > &rhs) -> std::common_type_t< frequency< Rep1, Precision1 >, frequency< Rep2, Precision2 > > |
| Returns the difference of two frequencies. | |
| template<typename Rep1 , typename Precision , typename Rep2 > requires not_frequency<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>> | |
| constexpr auto | freq::operator* (const frequency< Rep1, Precision > &f, const Rep2 &r) -> frequency< std::common_type_t< Rep1, Rep2 >, Precision > |
| Multiplies a frequency by a scalar. | |
| template<typename Rep1 , typename Rep2 , typename Precision > requires not_frequency<Rep1> && std::convertible_to<const Rep1&, std::common_type_t<Rep1, Rep2>> | |
| constexpr auto | freq::operator* (const Rep1 &r, const frequency< Rep2, Precision > &f) -> frequency< std::common_type_t< Rep1, Rep2 >, Precision > |
| Multiplies a scalar by a frequency. | |
| template<typename Rep1 , typename Precision , typename Rep2 > requires not_frequency<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>> | |
| constexpr auto | freq::operator/ (const frequency< Rep1, Precision > &f, const Rep2 &s) -> frequency< std::common_type_t< Rep1, Rep2 >, Precision > |
| Divides a frequency by a scalar. | |
| template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 > | |
| constexpr auto | freq::operator/ (const frequency< Rep1, Precision1 > &lhs, const frequency< Rep2, Precision2 > &rhs) -> std::common_type_t< Rep1, Rep2 > |
| Divides two frequencies, returning a scalar. | |
| template<typename Rep1 , typename Precision , typename Rep2 > requires not_frequency<Rep2> && std::convertible_to<const Rep2&, std::common_type_t<Rep1, Rep2>> && (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>) | |
| constexpr auto | freq::operator% (const frequency< Rep1, Precision > &f, const Rep2 &s) -> frequency< std::common_type_t< Rep1, Rep2 >, Precision > |
| Returns the remainder of dividing a frequency by a scalar. | |
| template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 > requires (!treat_as_inexact_v<Rep1> && !treat_as_inexact_v<Rep2>) | |
| constexpr auto | freq::operator% (const frequency< Rep1, Precision1 > &lhs, const frequency< Rep2, Precision2 > &rhs) -> std::common_type_t< frequency< Rep1, Precision1 >, frequency< Rep2, Precision2 > > |
| Returns the remainder of dividing two frequencies. | |
| template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 > | |
| constexpr bool | freq::operator== (const frequency< Rep1, Precision1 > &lhs, const frequency< Rep2, Precision2 > &rhs) |
| template<typename Rep1 , typename Precision1 , typename Rep2 , typename Precision2 > requires std::three_way_comparable<std::common_type_t<Rep1, Rep2>> | |
| constexpr auto | freq::operator<=> (const frequency< Rep1, Precision1 > &lhs, const frequency< Rep2, Precision2 > &rhs) |
| template<typename Rep , typename Precision > requires (!treat_as_inexact_v<Rep>) | |
| std::string | freq::to_string (const frequency< Rep, Precision > &f) |
| Renders a frequency as its exact count with a precision-qualified unit, e.g. | |
| template<char... Digits> | |
| constexpr freq::millihertz | frequency_literals::operator""_mHz () |
| Literal for millihertz (e.g., 1000_mHz). | |
| template<char... Digits> | |
| constexpr freq::hertz | frequency_literals::operator""_Hz () |
| Literal for hertz (e.g., 1000_Hz). | |
| template<char... Digits> | |
| constexpr freq::kilohertz | frequency_literals::operator""_kHz () |
| Literal for kilohertz (e.g., 80_kHz). | |
| template<char... Digits> | |
| constexpr freq::megahertz | frequency_literals::operator""_MHz () |
| Literal for megahertz (e.g., 80_MHz). | |
| template<char... Digits> | |
| constexpr freq::gigahertz | frequency_literals::operator""_GHz () |
| Literal for gigahertz (e.g., 2_GHz). | |
| template<char... Digits> | |
| constexpr freq::terahertz | frequency_literals::operator""_THz () |
| Literal for terahertz (e.g., 1_THz). | |
Variables | |
| template<typename T > | |
| constexpr bool | freq::is_frequency_v = is_frequency<T>::value |
| #define CONFIG_FREQUENCY_STD_FORMAT 0 |
Definition at line 19 of file frequency.hpp.