fixed_point (deprecated)  rev.2
Binary Fixed-Point Arithmetic Library in C++
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
sg14::fixed_point< Rep, Exponent > Class Template Reference

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::numeric_limits< S >::is_iec559, int > Dummy = 0>
constexpr fixed_point (S s)
 constructor taking a floating-point type
 
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::numeric_limits< S >::is_iec559, int > Dummy = 0>
constexpr operator S () const
 returns value represented as floating-point
 
template<typename R = Rep>
constexpr operator typename std::enable_if< std::is_convertible< Rep, bool >::value, bool > () const
 returns value represented as bool
 
template<class S , _impl::enable_if_t< std::numeric_limits< S >::is_integer, int > Dummy = 0>
fixed_pointoperator= (S s)
 copy assignment operator taking an integer type
 
template<class S , _impl::enable_if_t< std::numeric_limits< S >::is_iec559, int > Dummy = 0>
fixed_pointoperator= (S s)
 copy assignment operator taking a floating-point type
 
template<class FromRep , int FromExponent>
fixed_pointoperator= (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
 

Detailed Description

template<class Rep, int Exponent>
class sg14::fixed_point< Rep, Exponent >

literal real number approximation that uses fixed-point arithmetic

Template Parameters
Repthe underlying type used to represent the value
Exponentthe value by which to scale the integer value in order to get the real value
Examples

To define a fixed-point value 1 byte in size with a sign bit, 3 integer bits and 4 fractional bits:

constexpr auto n = fixed_point<char, -3>{-2.75};
static_assert(n==-2.75, "fixed-point type was unable to store the value");