|
fixed_point
rev.2
Binary Fixed-Point Arithmetic Library in C++
|
literal real number approximation that uses fixed-point arithmetic More...
#include <sg14/fixed_point>
Inherits sg14::_impl::number_base< fixed_point< Rep, Exponent >, Rep >.
Public Types | |
| using | rep = Rep |
| alias to template parameter, Rep | |
Public Member Functions | |
| constexpr | fixed_point () |
| default constructor | |
| template<class FromRep , int FromExponent> | |
| constexpr | fixed_point (const fixed_point< FromRep, FromExponent > &rhs) |
| constructor taking a fixed-point type | |
| template<class Integral , Integral Constant> | |
| constexpr | fixed_point (const std::integral_constant< Integral, Constant > &) |
| constructor taking an integral_constant type | |
| template<class S , _impl::enable_if_t< std::numeric_limits< S >::is_integer, int > Dummy = 0> | |
| constexpr | fixed_point (const S &s) |
| constructor taking an integer type | |
| template<class Integral , Integral Value, int Digits> | |
| constexpr | fixed_point (const_integer< Integral, Value, Digits, Exponent > ci) |
| constructor taking an integral_constant type | |
| template<class S , _impl::enable_if_t< std::is_floating_point< S >::value, int > Dummy = 0> | |
| constexpr | fixed_point (S s) |
| constructor taking a floating-point type | |
| constexpr | operator bool () const |
| returns value represented as bool | |
| template<class S , _impl::enable_if_t< std::numeric_limits< S >::is_integer, int > Dummy = 0> | |
| constexpr | operator S () const |
| returns value represented as integral | |
| template<class S , _impl::enable_if_t< std::is_floating_point< S >::value, int > Dummy = 0> | |
| constexpr | operator S () const |
| returns value represented as floating-point | |
| template<class S , _impl::enable_if_t< std::numeric_limits< S >::is_integer, int > Dummy = 0> | |
| fixed_point & | operator= (S s) |
| copy assignment operator taking an integer type | |
| template<class S , _impl::enable_if_t< std::is_floating_point< S >::value, int > Dummy = 0> | |
| fixed_point & | operator= (S s) |
| copy assignment operator taking a floating-point type | |
| template<class FromRep , int FromExponent> | |
| fixed_point & | operator= (const fixed_point< FromRep, FromExponent > &rhs) |
| copy assignement operator taking a fixed-point type | |
Static Public Member Functions | |
| static constexpr fixed_point | from_data (rep const &r) |
| creates an instance given the underlying representation value | |
Static Public Attributes | |
| static constexpr int | digits = std::numeric_limits<Rep>::digits |
| number of binary digits this type can represent; equivalent to std::numeric_limits::digits | |
| static constexpr int | exponent = Exponent |
| value of template parameter, Exponent | |
| static constexpr int | fractional_digits = -exponent |
| number of binary digits devoted to fractional part of value; can be negative for specializations with especially large ranges | |
| static constexpr int | integer_digits = digits+exponent |
| number of binary digits devoted to integer part of value; can be negative for specializations with especially small ranges | |
literal real number approximation that uses fixed-point arithmetic
| Rep | the underlying type used to represent the value |
| Exponent | the value by which to scale the integer value in order to get the real value |
To define a fixed-point value 1 byte in size with a sign bit, 3 integer bits and 4 fractional bits:
1.8.13