CNL  2.0.2 (development)
Compositional Numeric Library
cnl::literals Namespace Reference

user-defined literals More...

Functions

template<char... Chars>
constexpr auto operator""_cnl ()
 generate an elastic_scaled_integer object using a literal More...
 
template<char... Chars>
constexpr auto operator""_cnl2 ()
 generate an elastic_scaled_integer object using a binary literal More...
 

Detailed Description

user-defined literals

Function Documentation

◆ operator""_cnl()

template<char... Chars>
constexpr auto cnl::literals::operator""_cnl ( )
constexpr

generate an elastic_scaled_integer object using a literal

Template Parameters
Digitsthe characters of the literal sequence
Returns
the given value to be represented using an elastic_scaled_integer type
Note
The return type is guaranteed to be no larger than is necessary to represent the maximum value of Integral.
Example

To define a decimal fixed-point object with value 3.141:

using namespace cnl::literals;
constexpr auto n = 3.141_cnl;
static_assert(n == 3.141);
static_assert(
elastic_scaled_integer<12, power<-3, 10>> const,
decltype(n)>::value);

◆ operator""_cnl2()

template<char... Chars>
constexpr auto cnl::literals::operator""_cnl2 ( )
constexpr

generate an elastic_scaled_integer object using a binary literal

Template Parameters
Digitsthe characters of the literal sequence
Precondition
Sequence must be representable using binary fractions. E.g. 0.1_cnl2 cannot be represented using binary fixed-point numbers. This will not compile.
Returns
the given value to be represented using an elastic_scaled_integer type
Note
The return type is guaranteed to be no larger than is necessary to represent the maximum value of Integral.
std::is_same
cnl::elastic_scaled_integer
scaled_integer< elastic_integer< Digits, Narrowest >, Scale > elastic_scaled_integer
literal real number approximation that uses fixed-point arithmetic and auto-widens to avoid overflow
Definition: elastic_scaled_integer.h:41
cnl::literals
user-defined literals
Definition: literals.h:17