fixed_point (deprecated)
rev.2
Binary Fixed-Point Arithmetic Library in C++
|
study group 14 of the C++ working group More...
Namespaces | |
literals | |
generate an sg14::elastic_fixed_point object using a literal | |
Classes | |
class | const_integer |
a compile-time-only integer type like a std::integral_constant with arithmetic support More... | |
class | elastic_integer |
literal integer type that encodes its width in bits within its type More... | |
class | fixed_point |
literal real number approximation that uses fixed-point arithmetic More... | |
Typedefs | |
template<int IntegerDigits, int FractionalDigits = 0, class Narrowest = signed> | |
using | elastic_fixed_point = fixed_point< elastic_integer< IntegerDigits+FractionalDigits, Narrowest >, -FractionalDigits > |
literal real number approximation that uses fixed-point arithmetic and auto-widens to avoid overflow More... | |
template<int IntegerDigits, int FractionalDigits = 0, class Narrowest = signed> | |
using | make_fixed = fixed_point< set_digits_t< Narrowest, IntegerDigits+FractionalDigits >, -FractionalDigits > |
specializes fixed_point with the given number of integer and fractional digits More... | |
template<int IntegerDigits, int FractionalDigits = 0, class Narrowest = unsigned> | |
using | make_ufixed = make_fixed< IntegerDigits, FractionalDigits, typename make_unsigned< Narrowest >::type > |
specializes fixed_point with the given number of integer and fractional digits; produces an unsigned type More... | |
Functions | |
template<class Lhs , class Rhs > | |
constexpr auto | add (const Lhs &lhs, const Rhs &rhs) -> decltype(_impl::fp::operate< _impl::fp::named_function_tag >(lhs, rhs, _impl::add_tag)) |
calculates the sum of two fixed_point values More... | |
template<class Lhs , class Rhs > | |
constexpr auto | divide (const Lhs &lhs, const Rhs &rhs) -> decltype(_impl::fp::operate< _impl::fp::division_named_function_tag >(lhs, rhs, _impl::divide_tag)) |
calculates the quotient of two fixed_point values More... | |
template<class Rep , int Exponent> | |
constexpr fixed_point< Rep, Exponent > | exp2 (fixed_point< Rep, Exponent > x) |
Calculates exp2(x), i.e. 2^xAccurate to 1LSB for up to 32 bit underlying representation. More... | |
template<typename Narrowest = int, typename Integral = int, Integral Value = 0> | |
constexpr elastic_fixed_point< _impl::max(_impl::used_bits_symmetric(Value), 1), -trailing_bits(Value), Narrowest > | make_elastic_fixed_point (const_integer< Integral, Value >=const_integer< Integral, Value >{}) |
generate an sg14::elastic_fixed_point object of given value More... | |
template<class Narrowest = int, class Integral = int> | |
constexpr elastic_fixed_point< std::numeric_limits< Integral >::digits, 0, Narrowest > | make_elastic_fixed_point (Integral value) |
generate an sg14::elastic_fixed_point object of given value More... | |
template<class Lhs , class Rhs > | |
constexpr auto | multiply (const Lhs &lhs, const Rhs &rhs) -> decltype(_impl::fp::operate< _impl::fp::named_function_tag >(lhs, rhs, _impl::multiply_tag)) |
calculates the product of two fixed_point factors More... | |
template<class RhsRep , int RhsExponent> | |
constexpr auto | negate (const fixed_point< RhsRep, RhsExponent > &rhs) -> fixed_point< decltype(-rhs.data()), RhsExponent > |
calculates the negative of a fixed_point value More... | |
template<class Rep , int Exponent> | |
constexpr fixed_point< Rep, Exponent > | sqrt (const fixed_point< Rep, Exponent > &x) |
calculates the square root of a fixed_point value More... | |
template<class Lhs , class Rhs > | |
constexpr auto | subtract (const Lhs &lhs, const Rhs &rhs) -> decltype(_impl::fp::operate< _impl::fp::named_function_tag >(lhs, rhs, _impl::subtract_tag)) |
calculates the difference of two fixed_point values More... | |
study group 14 of the C++ working group
using sg14::elastic_fixed_point = typedef fixed_point<elastic_integer<IntegerDigits+FractionalDigits, Narrowest>, -FractionalDigits> |
literal real number approximation that uses fixed-point arithmetic and auto-widens to avoid overflow
IntegerDigits | the number of integer digits that can be stored |
FractionalDigits | the number of fractional digits that can be stored |
Narrowest | the most narrow integer type to use to represent values |
using sg14::make_fixed = typedef fixed_point< set_digits_t<Narrowest, IntegerDigits+FractionalDigits>, -FractionalDigits> |
specializes fixed_point with the given number of integer and fractional digits
IntegerDigits | specifies minimum value of fixed_point::integer_digits |
FractionalDigits | specifies the exact value of fixed_point::fractional_digits |
Narrowest | hints at the type of fixed_point::rep |
signed
and unsigned
, result in a type that uses built-in integers for fixed_point::rep. To generate a fixed-point type with a sign bit, 8 fractional bits and at least 7 integer bits:
using sg14::make_ufixed = typedef make_fixed< IntegerDigits, FractionalDigits, typename make_unsigned<Narrowest>::type> |
specializes fixed_point with the given number of integer and fractional digits; produces an unsigned type
constexpr auto sg14::add | ( | const Lhs & | lhs, |
const Rhs & | rhs | ||
) | -> decltype(_impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::add_tag)) |
calculates the sum of two fixed_point values
lhs,rhs | augend and addend |
constexpr auto sg14::divide | ( | const Lhs & | lhs, |
const Rhs & | rhs | ||
) | -> decltype(_impl::fp::operate<_impl::fp::division_named_function_tag>(lhs, rhs, _impl::divide_tag)) |
calculates the quotient of two fixed_point values
lhs,rhs | dividend and divisor |
constexpr fixed_point<Rep, Exponent> sg14::exp2 | ( | fixed_point< Rep, Exponent > | x | ) |
Calculates exp2(x), i.e. 2^xAccurate to 1LSB for up to 32 bit underlying representation.
x | the input value as a fixed_point |
constexpr elastic_fixed_point<_impl::max(_impl::used_bits_symmetric(Value), 1), -trailing_bits(Value), Narrowest> sg14::make_elastic_fixed_point | ( | const_integer< Integral, Value > | = const_integer<Integral, Value>{} | ) |
generate an sg14::elastic_fixed_point object of given value
Narrowest | the narrowest type to use as storage in the resultant sg14::elastic_fixed_point object |
Integral | the type of Value |
Value | the integer number to be represented |
To define an int-sized object using make_elastic_fixed_point and const_integer:
Referenced by make_elastic_fixed_point().
constexpr elastic_fixed_point<std::numeric_limits<Integral>::digits, 0, Narrowest> sg14::make_elastic_fixed_point | ( | Integral | value | ) |
generate an sg14::elastic_fixed_point object of given value
Narrowest | the most narrow storage type of the resultant sg14::elastic_fixed_point object |
Integral | the type of value |
To define a byte-sized object using make_elastic_fixed_point and _c:
References make_elastic_fixed_point().
constexpr auto sg14::multiply | ( | const Lhs & | lhs, |
const Rhs & | rhs | ||
) | -> decltype(_impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::multiply_tag)) |
calculates the product of two fixed_point factors
lhs,rhs | the factors |
constexpr auto sg14::negate | ( | const fixed_point< RhsRep, RhsExponent > & | rhs | ) | -> fixed_point<decltype(-rhs.data()), RhsExponent> |
calculates the negative of a fixed_point value
rhs | input value |
constexpr fixed_point<Rep, Exponent> sg14::sqrt | ( | const fixed_point< Rep, Exponent > & | x | ) |
calculates the square root of a fixed_point value
x | input parameter |
References sg14::fixed_point< Rep, Exponent >::from_data().
constexpr auto sg14::subtract | ( | const Lhs & | lhs, |
const Rhs & | rhs | ||
) | -> decltype(_impl::fp::operate<_impl::fp::named_function_tag>(lhs, rhs, _impl::subtract_tag)) |
calculates the difference of two fixed_point values
lhs,rhs | minuend and subtrahend |