Skip to content

Instantly share code, notes, and snippets.

@johnmcfarlane
Created July 9, 2016 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnmcfarlane/8ad2d9d3fc5916e1b8d359fa4ee2dade to your computer and use it in GitHub Desktop.
Save johnmcfarlane/8ad2d9d3fc5916e1b8d359fa4ee2dade to your computer and use it in GitHub Desktop.
Result of running fixed_point.h through standardese

Header file fixed_point.h

#define SG14_FIXED_POINT_H 1

#include "type_traits.h"

#include "bits/common.h"

#define SG14_FIXED_POINT_EXCEPTIONS_ENABLED

#include

#include "bits/fixed_point_extras.h"

namespace sg14 { namespace _fixed_point_impl { template using digits = std::integral_constant<int, width::value-is_signed::value>;

    template <typename T>
    using float_of_same_size = set_width_t<float, width<T>::value>;
    
    template <typename IntType>
    using next_size = typename sg14::set_width_t<IntType, width<IntType>::value*2>;
    
    template <typename IntType>
    using previous_size = typename sg14::set_width_t<IntType, width<IntType>::value/2>;
    
    template <typename S, int Exponent, typename std::enable_if<Exponent==0, int>::type Dummy = 0>
    constexpr S pow2();
    
    template <typename S, int Exponent, typename std::enable_if<!(Exponent<=0) && (Exponent<8), int>::type Dummy = 0>
    constexpr S pow2();
    
    template <typename S, int Exponent, typename std::enable_if<(Exponent>=8), int>::type Dummy = 0>
    constexpr S pow2();
    
    template <typename S, int Exponent, typename std::enable_if<!(Exponent>=0) && (Exponent>-8), int>::type Dummy = 0>
    constexpr S pow2();
    
    template <typename S, int Exponent, typename std::enable_if<(Exponent<=-8), int>::type Dummy = 0>
    constexpr S pow2();
    
    template <int Exponent, typename Output, typename Input, typename std::enable_if<
    (Exponent==0),
    int>::type Dummy = 0>
    constexpr Output shift_left(Input i);
    
    template <int Exponent, typename Output, typename Input, typename std::enable_if<
    Exponent==0,
    int>::type Dummy = 0>
    constexpr Output shift_right(Input i);
    
    template <int Exponent, typename Output, typename Input, typename std::enable_if<
    !(Exponent<=0),
    int>::type Dummy = 0>
    constexpr Output shift_left(Input i);
    
    template <int Exponent, typename Output, typename Input, typename std::enable_if<
    !(Exponent<=0),
    int>::type Dummy = 0>
    constexpr Output shift_right(Input i);
    
    template <int Exponent, typename Output, typename Input, typename std::enable_if<
    (Exponent<0),
    int>::type Dummy = 0>
    constexpr Output shift_left(Input i);
    
    template <int Exponent, typename Output, typename Input, typename std::enable_if<
    Exponent<0,
    int>::type Dummy = 0>
    constexpr Output shift_right(Input i);
    
    template <>
    struct capacity<0>;
    
    template <unsigned N>
    struct capacity;}

template <typename Rep = int, int Exponent = 0>
class fixed_point;

template <int IntegerDigits, int FractionalDigits = 0, typename Archetype = signed>
using make_fixed = fixed_point<
set_width_t<Archetype, IntegerDigits+FractionalDigits+is_signed<Archetype>::value>,
-FractionalDigits>;

template <int IntegerDigits, int FractionalDigits = 0, typename Archetype = unsigned>
using make_ufixed = make_fixed<
IntegerDigits,
FractionalDigits,
typename make_unsigned<Archetype>::type>;

namespace _fixed_point_impl
{
    template <typename T>
    struct is_fixed_point;
    
    template <typename Rep, int Exponent>
    struct is_fixed_point;
    
    template <typename LhsRep, int LhsExponent, typename RhsInteger>
    struct common_type_mixed<
    fixed_point<LhsRep, LhsExponent>,
    RhsInteger,
    typename std::enable_if<is_integral<RhsInteger>::value>::type>;
    
    template <typename LhsRep, int LhsExponent, typename Float>
    struct common_type_mixed<
    fixed_point<LhsRep, LhsExponent>,
    Float,
    typename std::enable_if<std::is_floating_point<Float>::value>::type>;}}

namespace std{}

namespace sg14 { namespace _fixed_point_impl { template <typename LhsRep, int LhsExponent, typename RhsRep, int RhsExponent> struct binary_pair_base;

    template <typename LhsRep, int LhsExponent, typename RhsRep, int RhsExponent>
    struct binary_pair<fixed_point<LhsRep, LhsExponent>;
    
    template <typename LhsRep, int LhsExponent, typename Rhs>
    struct binary_pair<fixed_point<LhsRep, LhsExponent>, Rhs>;
    
    template <typename Lhs, typename RhsRep, int RhsExponent>
    struct binary_pair;
    
    template <typename BinaryPair>
    struct multiply_lean;
    
    template <typename BinaryPair>
    struct multiply_wide;
    
    using named_function_tag = lean_tag;
    
    using arithmetic_operator_tag = wide_tag;
    
    template <typename Rhs>
    struct rep_op<negate_tag, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct rep_op<add_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct rep_op<subtract_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct rep_op<multiply_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct rep_op<divide_tag, Lhs, Rhs>;
    
    template <typename OperationTag, typename Lhs, typename Rhs>
    constexpr decltype(rep_op<OperationTag, Lhs, Rhs>::op(lhs, rhs)) rep_op_fn(const Lhs& lhs, const Rhs& rhs);
    
    template <typename OperationTag, typename Lhs, typename Rhs>
    using rep_op_result = decltype(rep_op_fn<OperationTag, typename Lhs::rep, typename Rhs::rep>(
    std::declval<typename Lhs::rep>(), std::declval<typename Rhs::rep>()));
    
    template <typename Rhs>
    struct bare_exponent<negate_tag, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct bare_exponent<add_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct bare_exponent<subtract_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct bare_exponent<multiply_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct bare_exponent<divide_tag, Lhs, Rhs>;
    
    template <typename OperationTag, typename Lhs, typename Rhs>
    struct intermediate<OperationTag, bare_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct intermediate<add_tag, lean_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct intermediate<subtract_tag, lean_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct intermediate<multiply_tag, lean_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct intermediate<divide_tag, lean_tag, Lhs, Rhs>;
    
    template <typename OperationTag, typename Lhs, typename Rhs>
    struct intermediate<OperationTag, wide_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct intermediate<multiply_tag, wide_tag, Lhs, Rhs>;
    
    template <typename Lhs, typename Rhs>
    struct intermediate<divide_tag, wide_tag, Lhs, Rhs>;
    
    template <typename OperationTag, typename Lhs, typename Rhs>
    struct operate_params<OperationTag, bare_tag, Lhs, Rhs>;
    
    template <typename OperationTag, typename PolicyTag, typename Lhs, typename Rhs>
    struct operate_params;
    
    template <typename OperationTag, typename PolicyTag, typename Lhs, typename Rhs>
    constexpr typename operate_params<OperationTag, PolicyTag, Lhs, Rhs>::result_type operate(const Lhs& lhs, const Rhs& rhs);}

template <typename RhsRep, int RhsExponent>
constexpr fixed_point<decltype(-rhs.data()), RhsExponent> negate(const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename Lhs, typename Rhs>
constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::add_tag, _fixed_point_impl::named_function_tag>(lhs, rhs)) add(const Lhs& lhs, const Rhs& rhs);

template <typename Lhs, typename Rhs>
constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::subtract_tag, _fixed_point_impl::named_function_tag>(lhs,
rhs)) subtract(const Lhs& lhs, const Rhs& rhs);

template <typename Lhs, typename Rhs>
constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::multiply_tag, _fixed_point_impl::named_function_tag>(lhs,
rhs)) multiply(const Lhs& lhs, const Rhs& rhs);

template <typename Lhs, typename Rhs>
constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::divide_tag, _fixed_point_impl::named_function_tag>(lhs,
rhs)) divide(const Lhs& lhs, const Rhs& rhs);

template <typename Rep, int Exponent>
constexpr bool operator==(const fixed_point<Rep, Exponent>& lhs, const fixed_point<Rep, Exponent>& rhs);

template <typename Rep, int Exponent>
constexpr bool operator!=(const fixed_point<Rep, Exponent>& lhs, const fixed_point<Rep, Exponent>& rhs);

template <typename Rep, int Exponent>
constexpr bool operator<(const fixed_point<Rep, Exponent>& lhs, const fixed_point<Rep, Exponent>& rhs);

template <typename Rep, int Exponent>
constexpr bool operator>(const fixed_point<Rep, Exponent>& lhs, const fixed_point<Rep, Exponent>& rhs);

template <typename Rep, int Exponent>
constexpr bool operator>=(const fixed_point<Rep, Exponent>& lhs, const fixed_point<Rep, Exponent>& rhs);

template <typename Rep, int Exponent>
constexpr bool operator<=(const fixed_point<Rep, Exponent>& lhs, const fixed_point<Rep, Exponent>& rhs);

template <typename RhsRep, int RhsExponent>
constexpr fixed_point<decltype(-rhs.data()), RhsExponent> operator-(const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsRep, int LhsExponent, typename RhsRep, int RhsExponent>
constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::add_tag, _fixed_point_impl::arithmetic_operator_tag>(lhs,
rhs)) operator+(const fixed_point<LhsRep, LhsExponent>& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsRep, int LhsExponent, typename RhsRep, int RhsExponent>
constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::subtract_tag, _fixed_point_impl::arithmetic_operator_tag>(
lhs, rhs)) operator-(const fixed_point<LhsRep, LhsExponent>& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsRep, int LhsExponent, typename RhsRep, int RhsExponent>
constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::multiply_tag, _fixed_point_impl::arithmetic_operator_tag>(
lhs, rhs)) operator*(const fixed_point<LhsRep, LhsExponent>& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsRep, int LhsExponent, typename RhsRep, int RhsExponent>
constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::divide_tag, _fixed_point_impl::arithmetic_operator_tag>(
lhs, rhs)) operator/(const fixed_point<LhsRep, LhsExponent>& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename Lhs, typename Rhs>
constexpr typename std::enable_if<
_fixed_point_impl::is_fixed_point<Lhs>::value || _fixed_point_impl::is_fixed_point<Rhs>::value, bool>::type operator==(const Lhs& lhs, const Rhs& rhs);

template <typename Lhs, typename Rhs>
constexpr typename std::enable_if<
_fixed_point_impl::is_fixed_point<Lhs>::value || _fixed_point_impl::is_fixed_point<Rhs>::value, bool>::type operator!=(const Lhs& lhs, const Rhs& rhs);

template <typename Lhs, typename Rhs>
constexpr typename std::enable_if<
_fixed_point_impl::is_fixed_point<Lhs>::value || _fixed_point_impl::is_fixed_point<Rhs>::value, bool>::type operator<(const Lhs& lhs, const Rhs& rhs);

template <typename Lhs, typename Rhs>
constexpr typename std::enable_if<
_fixed_point_impl::is_fixed_point<Lhs>::value || _fixed_point_impl::is_fixed_point<Rhs>::value, bool>::type operator>(const Lhs& lhs, const Rhs& rhs);

template <typename Lhs, typename Rhs>
constexpr typename std::enable_if<
_fixed_point_impl::is_fixed_point<Lhs>::value || _fixed_point_impl::is_fixed_point<Rhs>::value, bool>::type operator>=(const Lhs& lhs, const Rhs& rhs);

template <typename Lhs, typename Rhs>
constexpr typename std::enable_if<
_fixed_point_impl::is_fixed_point<Lhs>::value || _fixed_point_impl::is_fixed_point<Rhs>::value, bool>::type operator<=(const Lhs& lhs, const Rhs& rhs);

template <typename LhsRep, int LhsExponent, typename RhsInteger, typename = typename std::enable_if<is_integral<RhsInteger>::value>::type>
constexpr decltype(lhs + fixed_point<RhsInteger, 0> operator+(const fixed_point<LhsRep, LhsExponent>& lhs, const RhsInteger& rhs);

template <typename LhsRep, int LhsExponent, typename RhsInteger, typename = typename std::enable_if<is_integral<RhsInteger>::value>::type>
constexpr decltype(lhs - fixed_point<RhsInteger, 0> operator-(const fixed_point<LhsRep, LhsExponent>& lhs, const RhsInteger& rhs);

template <typename LhsRep, int LhsExponent, typename RhsInteger, typename = typename std::enable_if<is_integral<RhsInteger>::value>::type>
constexpr decltype(lhs*fixed_point<RhsInteger>(rhs)) operator*(const fixed_point<LhsRep, LhsExponent>& lhs, const RhsInteger& rhs);

template <typename LhsRep, int LhsExponent, typename RhsInteger, typename = typename std::enable_if<is_integral<RhsInteger>::value>::type>
constexpr decltype(lhs/fixed_point<RhsInteger> operator/(const fixed_point<LhsRep, LhsExponent>& lhs, const RhsInteger& rhs);

template <typename LhsInteger, typename RhsRep, int RhsExponent, typename = typename std::enable_if<is_integral<LhsInteger>::value>::type>
constexpr decltype(fixed_point<LhsInteger, 0> operator+(const LhsInteger& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsInteger, typename RhsRep, int RhsExponent, typename = typename std::enable_if<is_integral<LhsInteger>::value>::type>
constexpr decltype(fixed_point<LhsInteger> operator-(const LhsInteger& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsInteger, typename RhsRep, int RhsExponent, typename = typename std::enable_if<is_integral<LhsInteger>::value>::type>
constexpr decltype(fixed_point<LhsInteger> operator*(const LhsInteger& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsInteger, typename RhsRep, int RhsExponent, typename = typename std::enable_if<is_integral<LhsInteger>::value>::type>
constexpr decltype(fixed_point<LhsInteger> operator/(const LhsInteger& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsRep, int LhsExponent, typename RhsFloat, typename = typename std::enable_if<std::is_floating_point<RhsFloat>::value>::type>
constexpr _impl::common_type_t<fixed_point<LhsRep, LhsExponent>, RhsFloat> operator+(const fixed_point<LhsRep, LhsExponent>& lhs, const RhsFloat& rhs);

template <typename LhsRep, int LhsExponent, typename RhsFloat, typename = typename std::enable_if<std::is_floating_point<RhsFloat>::value>::type>
constexpr _impl::common_type_t<fixed_point<LhsRep, LhsExponent>, RhsFloat> operator-(const fixed_point<LhsRep, LhsExponent>& lhs, const RhsFloat& rhs);

template <typename LhsRep, int LhsExponent, typename RhsFloat>
constexpr _impl::common_type_t<
fixed_point<LhsRep, LhsExponent>,
typename std::enable_if<std::is_floating_point<RhsFloat>::value, RhsFloat>::type> operator*(const fixed_point<LhsRep, LhsExponent>& lhs, const RhsFloat& rhs);

template <typename LhsRep, int LhsExponent, typename RhsFloat>
constexpr _impl::common_type_t<
fixed_point<LhsRep, LhsExponent>,
typename std::enable_if<std::is_floating_point<RhsFloat>::value, RhsFloat>::type> operator/(const fixed_point<LhsRep, LhsExponent>& lhs, const RhsFloat& rhs);

template <typename LhsFloat, typename RhsRep, int RhsExponent, typename = typename std::enable_if<std::is_floating_point<LhsFloat>::value>::type>
constexpr _impl::common_type_t<LhsFloat, fixed_point<RhsRep, RhsExponent>> operator+(const LhsFloat& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsFloat, typename RhsRep, int RhsExponent, typename = typename std::enable_if<std::is_floating_point<LhsFloat>::value>::type>
constexpr _impl::common_type_t<LhsFloat, fixed_point<RhsRep, RhsExponent>> operator-(const LhsFloat& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsFloat, typename RhsRep, int RhsExponent>
constexpr _impl::common_type_t<
typename std::enable_if<std::is_floating_point<LhsFloat>::value, LhsFloat>::type,
fixed_point<RhsRep, RhsExponent>> operator*(const LhsFloat& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsFloat, typename RhsRep, int RhsExponent>
constexpr _impl::common_type_t<
typename std::enable_if<std::is_floating_point<LhsFloat>::value, LhsFloat>::type,
fixed_point<RhsRep, RhsExponent>> operator/(const LhsFloat& lhs, const fixed_point<RhsRep, RhsExponent>& rhs);

template <typename LhsRep, int Exponent, typename Rhs>
fixed_point<LhsRep, Exponent>& operator+=(fixed_point<LhsRep, Exponent>& lhs, const Rhs& rhs);

template <typename LhsRep, int Exponent, typename Rhs>
fixed_point<LhsRep, Exponent>& operator-=(fixed_point<LhsRep, Exponent>& lhs, const Rhs& rhs);

template <typename LhsRep, int LhsExponent, typename Rhs>
constexpr fixed_point<LhsRep, LhsExponent> operator<<(const fixed_point<LhsRep, LhsExponent>& lhs, const Rhs& rhs);

template <typename LhsRep, int LhsExponent, typename Rhs>
constexpr fixed_point<LhsRep, LhsExponent> operator>>(const fixed_point<LhsRep, LhsExponent>& lhs, const Rhs& rhs);}

Macro SG14_FIXED_POINT_H

#define SG14_FIXED_POINT_H 1

Macro SG14_FIXED_POINT_EXCEPTIONS_ENABLED

#define SG14_FIXED_POINT_EXCEPTIONS_ENABLED

Alias template sg14::_fixed_point_impl::digits

template using digits = std::integral_constant<int, width::value-is_signed::value>;

Alias template sg14::_fixed_point_impl::float_of_same_size

template using float_of_same_size = set_width_t<float, width::value>;

Alias template sg14::_fixed_point_impl::next_size

template using next_size = typename sg14::set_width_t<IntType, width::value*2>;

Alias template sg14::_fixed_point_impl::previous_size

template using previous_size = typename sg14::set_width_t<IntType, width::value/2>;

Function template sg14::_fixed_point_impl::pow2<S, Exponent, Dummy>

template <typename S, int Exponent, typename std::enable_if<Exponent==0, int>::type Dummy = 0> constexpr S pow2();

Function template sg14::_fixed_point_impl::shift_left<Exponent, Output, Input, Dummy>

template <int Exponent, typename Output, typename Input, typename std::enable_if< (Exponent==0), int>::type Dummy = 0> constexpr Output shift_left(Input i);

Class template sg14::_fixed_point_impl::capacity

template struct capacity { static constexpr int value = capacity<N/2>::+1; };

Class template sg14::fixed_point<Rep, Exponent>

template class fixed_point { public: using rep = Rep; static constexpr int exponent = Exponent; static constexpr int digits = _fixed_point_impl::::value; static constexpr int integer_digits = digits+exponent; static constexpr int fractional_digits = -exponent;

public: fixed_point(); template <typename S, typename std::enable_if<is_integral::value, int>::type Dummy = 0> explicit constexpr fixed_point(S s); template <typename S, typename std::enable_if<std::is_floating_point::value, int>::type Dummy = 0> explicit constexpr fixed_point(S s); template <typename FromRep, int FromExponent> explicit constexpr fixed_point(const fixed_point<FromRep, FromExponent>& rhs); template <typename S, typename std::enable_if<is_integral::value, int>::type Dummy = 0> fixed_point& operator=(S s); template <typename S, typename std::enable_if<std::is_floating_point::value, int>::type Dummy = 0> fixed_point& operator=(S s); template <typename FromRep, int FromExponent> fixed_point& operator=(const fixed_point<FromRep, FromExponent>& rhs); template <typename S, typename std::enable_if<is_integral::value, int>::type Dummy = 0> explicit constexpr operator S() const; template <typename S, typename std::enable_if<std::is_floating_point::value, int>::type Dummy = 0> explicit constexpr operator S() const; explicit constexpr operator bool() const; template fixed_point& operator*=(const Rhs& rhs); template fixed_point& operator/=(const Rhs& rhs); constexpr rep data() const; static constexpr fixed_point from_data(rep r); };

literal real number approximation that uses fixed-point arithmetic

To define a fixed-point value 1 byte in size with a sign bit, 3 integer bits and 4 fractional bits: \snippet snippets.cpp define a fixed_point value Type alias sg14::rep

using rep = Rep;

alias to template parameter, \a Rep Variable sg14::exponent

static constexpr int exponent = Exponent;

value of template parameter, \a Exponent Variable sg14::digits

static constexpr int digits = _fixed_point_impl::::value;

number of binary digits this type can represent; equivalent to std::numeric_limits::digits Variable sg14::integer_digits

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 Variable sg14::fractional_digits

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 Constructor sg14::fixed_point

fixed_point();

default constructor Function template sg14::fixed_point<S, Dummy>

template <typename S, typename std::enable_if<is_integral::value, int>::type Dummy = 0> explicit constexpr fixed_point(S s);

constructor taking an integer type Function template sg14::fixed_point<S, Dummy>

template <typename S, typename std::enable_if<std::is_floating_point::value, int>::type Dummy = 0> explicit constexpr fixed_point(S s);

constructor taking a floating-point type Function template sg14::fixed_point<FromRep, FromExponent>

template <typename FromRep, int FromExponent> explicit constexpr fixed_point(const fixed_point<FromRep, FromExponent>& rhs);

constructor taking a fixed-point type Function template sg14::operator=<S, Dummy>

template <typename S, typename std::enable_if<is_integral::value, int>::type Dummy = 0> fixed_point& operator=(S s);

copy assignment operator taking an integer type Function template sg14::operator=<S, Dummy>

template <typename S, typename std::enable_if<std::is_floating_point::value, int>::type Dummy = 0> fixed_point& operator=(S s);

copy assignment operator taking a floating-point type Function template sg14::operator=<FromRep, FromExponent>

template <typename FromRep, int FromExponent> fixed_point& operator=(const fixed_point<FromRep, FromExponent>& rhs);

copy assignement operator taking a fixed-point type Function template sg14::operator S<S, Dummy>

template <typename S, typename std::enable_if<is_integral::value, int>::type Dummy = 0> explicit constexpr operator S() const;

returns value represented as integral Function template sg14::operator S<S, Dummy>

template <typename S, typename std::enable_if<std::is_floating_point::value, int>::type Dummy = 0> explicit constexpr operator S() const;

returns value represented as floating-point Conversion operator sg14::operator bool

explicit constexpr operator bool() const;

returns non-zeroness represented as boolean Function sg14::data

constexpr rep data() const;

returns internal representation of value Function sg14::from_data

static constexpr fixed_point from_data(rep r);

creates an instance given the underlying representation value Alias template sg14::make_fixed<IntegerDigits, FractionalDigits, Archetype>

template <int IntegerDigits, int FractionalDigits = 0, typename Archetype = signed> using make_fixed = fixed_point< set_width_t<Archetype, IntegerDigits+FractionalDigits+is_signed::value>, -FractionalDigits>;

Produce a fixed-point type with the given number of integer and fractional digits.

Remarks: The signage of \a Archetype specifies signage of the resultant fixed-point type. \remarks Typical choices for \a Archetype, signed and unsigned, result in a type that uses built-in integers for \a fixed_point::rep. \remarks Resultant type is signed by default.

To generate a fixed-point type with a sign bit, 8 fractional bits and at least 7 integer bits: \snippet snippets.cpp use make_fixed Alias template sg14::make_ufixed<IntegerDigits, FractionalDigits, Archetype>

template <int IntegerDigits, int FractionalDigits = 0, typename Archetype = unsigned> using make_ufixed = make_fixed< IntegerDigits, FractionalDigits, typename make_unsigned::type>;

Produce an unsigned fixed-point type with the given number of integer and fractional digits. Class template sg14::_fixed_point_impl::is_fixed_point

template struct is_fixed_point : std::false_type {};

Class template sg14::_fixed_point_impl::operate_params<OperationTag, PolicyTag, Lhs, Rhs>

template <typename OperationTag, typename PolicyTag, typename Lhs, typename Rhs> struct operate_params { using binary_pair = _fixed_point_impl::binary_pair<Lhs, Rhs>; using lhs_type = typename binary_pair::lhs_type; using rhs_type = typename binary_pair::rhs_type; using intermediate = _fixed_point_impl::intermediate<OperationTag, PolicyTag, lhs_type, rhs_type>; using intermediate_lhs = typename intermediate::lhs_type; using intermediate_rhs = typename intermediate::rhs_type; using bare_traits = operate_params<OperationTag, bare_tag, intermediate_lhs, intermediate_rhs>; using result_type = typename bare_traits::result_type; };

Function template sg14::_fixed_point_impl::operate<OperationTag, PolicyTag, Lhs, Rhs>

template <typename OperationTag, typename PolicyTag, typename Lhs, typename Rhs> constexpr typename operate_params<OperationTag, PolicyTag, Lhs, Rhs>::result_type operate(const Lhs& lhs, const Rhs& rhs);

Function template sg14::negate<RhsRep, RhsExponent>

template <typename RhsRep, int RhsExponent> constexpr fixed_point<decltype(-rhs.data()), RhsExponent> negate(const fixed_point<RhsRep, RhsExponent>& rhs);

calculates the negative of a \ref fixed_point value Function template sg14::add<Lhs, Rhs>

template <typename Lhs, typename Rhs> constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::add_tag, _fixed_point_impl::named_function_tag>(lhs, rhs)) add(const Lhs& lhs, const Rhs& rhs);

calculates the sum of two \ref fixed_point values Function template sg14::subtract<Lhs, Rhs>

template <typename Lhs, typename Rhs> constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::subtract_tag, _fixed_point_impl::named_function_tag>(lhs, rhs)) subtract(const Lhs& lhs, const Rhs& rhs);

calculates the difference of two \ref fixed_point values Function template sg14::multiply<Lhs, Rhs>

template <typename Lhs, typename Rhs> constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::multiply_tag, _fixed_point_impl::named_function_tag>(lhs, rhs)) multiply(const Lhs& lhs, const Rhs& rhs);

calculates the product of two \ref fixed_point factors Function template sg14::divide<Lhs, Rhs>

template <typename Lhs, typename Rhs> constexpr decltype(_fixed_point_impl::operate<_fixed_point_impl::divide_tag, _fixed_point_impl::named_function_tag>(lhs, rhs)) divide(const Lhs& lhs, const Rhs& rhs);

calculates the quotient of two \ref fixed_point values Function template sg14::operator==<Lhs, Rhs>

template <typename Lhs, typename Rhs> constexpr typename std::enable_if< _fixed_point_impl::is_fixed_point::value || _fixed_point_impl::is_fixed_point::value, bool>::type operator==(const Lhs& lhs, const Rhs& rhs);

Function template sg14::operator<<<LhsRep, LhsExponent, Rhs>

template <typename LhsRep, int LhsExponent, typename Rhs> constexpr fixed_point<LhsRep, LhsExponent> operator<<(const fixed_point<LhsRep, LhsExponent>& lhs, const Rhs& rhs);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment