ATLAS Offline Software
Loading...
Searching...
No Matches
GlobalSim::ap_fixed< width, dp, S, T, WS > Struct Template Reference

#include <ap_fixed.h>

Collaboration diagram for GlobalSim::ap_fixed< width, dp, S, T, WS >:

Public Member Functions

 ap_fixed ()=default
 ap_fixed (const double d)
 ap_fixed (const double d)
 operator double () const
const ap_fixed operator+ (const ap_fixed &f) const
const ap_fixedoperator+= (const ap_fixed &f)
ap_fixed operator- (const ap_fixed &f) const
const ap_fixedoperator-= (const ap_fixed &f)
ap_fixed operator* (const ap_fixed &f) const
const ap_fixedoperator*= (const ap_fixed &f)
ap_fixed operator/ (const ap_fixed &f) const
const ap_fixedoperator/= (const ap_fixed &f)
ap_fixed operator- () const
void test_overflow ()

Static Public Member Functions

static ap_fixed form (T v)

Public Attributes

m_value = T{0}
bool m_ovflw {false}

Static Public Attributes

static constexpr T m_overflow_mask = max_to_overflow<width, T>()

Friends

std::ostream & operator<< (std::ostream &os, const ap_fixed< width, dp, S, T, WS > ap)

Detailed Description

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
struct GlobalSim::ap_fixed< width, dp, S, T, WS >

Definition at line 44 of file ap_fixed.h.

Constructor & Destructor Documentation

◆ ap_fixed() [1/3]

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
GlobalSim::ap_fixed< width, dp, S, T, WS >::ap_fixed ( )
default

◆ ap_fixed() [2/3]

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
GlobalSim::ap_fixed< width, dp, S, T, WS >::ap_fixed ( const double d)
inline

Definition at line 58 of file ap_fixed.h.

58 :
59 m_value(d * double (1<< dp) + (d >= 0 ? 0.5 : -0.5)){
61 }

◆ ap_fixed() [3/3]

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
GlobalSim::ap_fixed< width, dp, S, T, WS >::ap_fixed ( const double d)
inline

Definition at line 63 of file ap_fixed.h.

63 :
64 m_value(d * double (1<< dp) + (d >= 0 ? 0. : -1.0)){
66 }

Member Function Documentation

◆ form()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
ap_fixed GlobalSim::ap_fixed< width, dp, S, T, WS >::form ( T v)
inlinestatic

Definition at line 74 of file ap_fixed.h.

74 {
75 ap_fixed k; k.m_value = v; k.test_overflow();return k;
76 }

◆ operator double()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
GlobalSim::ap_fixed< width, dp, S, T, WS >::operator double ( ) const
inline

Definition at line 69 of file ap_fixed.h.

69 {
70 return double(this->m_value) / double(1 << dp);
71 }

◆ operator*()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
ap_fixed GlobalSim::ap_fixed< width, dp, S, T, WS >::operator* ( const ap_fixed< width, dp, S, T, WS > & f) const
inline

Definition at line 100 of file ap_fixed.h.

100 {
101 return form((WS(this->m_value) * WS(f.m_value)) >> dp);
102 }
static ap_fixed form(T v)
Definition ap_fixed.h:74

◆ operator*=()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
const ap_fixed & GlobalSim::ap_fixed< width, dp, S, T, WS >::operator*= ( const ap_fixed< width, dp, S, T, WS > & f)
inline

Definition at line 104 of file ap_fixed.h.

104 {
105 this->m_value = (WS(this->m_value) * WS(f.m_value) >> dp);
107 return *this;
108 }

◆ operator+()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
const ap_fixed GlobalSim::ap_fixed< width, dp, S, T, WS >::operator+ ( const ap_fixed< width, dp, S, T, WS > & f) const
inline

Definition at line 78 of file ap_fixed.h.

78 {
79 return form(this->m_value + f.m_value);
80 }

◆ operator+=()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
const ap_fixed & GlobalSim::ap_fixed< width, dp, S, T, WS >::operator+= ( const ap_fixed< width, dp, S, T, WS > & f)
inline

Definition at line 83 of file ap_fixed.h.

83 {
84 this->m_value += f.m_value;
86 return *this;
87 }

◆ operator-() [1/2]

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
ap_fixed GlobalSim::ap_fixed< width, dp, S, T, WS >::operator- ( ) const
inline

Definition at line 122 of file ap_fixed.h.

122 {
123 return form(-this->m_value);
124 }

◆ operator-() [2/2]

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
ap_fixed GlobalSim::ap_fixed< width, dp, S, T, WS >::operator- ( const ap_fixed< width, dp, S, T, WS > & f) const
inline

Definition at line 89 of file ap_fixed.h.

89 {
90 return form(this->m_value - f.m_value);
91 }

◆ operator-=()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
const ap_fixed & GlobalSim::ap_fixed< width, dp, S, T, WS >::operator-= ( const ap_fixed< width, dp, S, T, WS > & f)
inline

Definition at line 94 of file ap_fixed.h.

94 {
95 this->m_value -= f.m_value;
97 return *this;
98 }

◆ operator/()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
ap_fixed GlobalSim::ap_fixed< width, dp, S, T, WS >::operator/ ( const ap_fixed< width, dp, S, T, WS > & f) const
inline

Definition at line 111 of file ap_fixed.h.

111 {
112 return form((WS(this->m_value) << dp) / WS(f.m_value));
113 }

◆ operator/=()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
const ap_fixed & GlobalSim::ap_fixed< width, dp, S, T, WS >::operator/= ( const ap_fixed< width, dp, S, T, WS > & f)
inline

Definition at line 115 of file ap_fixed.h.

115 {
116 this->m_value = ((WS(this->m_value) << dp) / WS(f.m_value));
118 return *this;
119 }

◆ test_overflow()

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
void GlobalSim::ap_fixed< width, dp, S, T, WS >::test_overflow ( )
inline

Definition at line 126 of file ap_fixed.h.

126 {
127
128 if (m_value > 0) {
129 if (m_value & m_overflow_mask) {
130 m_ovflw=true;
131 }
132 } else {
133 if (-m_value & m_overflow_mask) {
134 m_ovflw=true;
135 }
136 }
137
138 if (m_ovflw) {
141
142 ss << "ap_fixed overflow. val: "
143 << m_value << " abs(val): " << val
144 << ' ' << std::hex << val
145 << " masked " << (val & m_overflow_mask);
146 throw std::out_of_range(ss.str());
147 }
148 }
static constexpr T m_overflow_mask
Definition ap_fixed.h:47

◆ operator<<

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
std::ostream & operator<< ( std::ostream & os,
const ap_fixed< width, dp, S, T, WS > ap )
friend

Definition at line 50 of file ap_fixed.h.

51 {
52 os << ap.m_value << ' ' << double(ap);
53 return os;
54 }

Member Data Documentation

◆ m_overflow_mask

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
T GlobalSim::ap_fixed< width, dp, S, T, WS >::m_overflow_mask = max_to_overflow<width, T>()
staticconstexpr

Definition at line 47 of file ap_fixed.h.

◆ m_ovflw

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
bool GlobalSim::ap_fixed< width, dp, S, T, WS >::m_ovflw {false}

Definition at line 49 of file ap_fixed.h.

49{false};

◆ m_value

template<std::size_t width, std::size_t dp, typename S = XilDef, typename T = int16_t, typename WS = int32_t>
T GlobalSim::ap_fixed< width, dp, S, T, WS >::m_value = T{0}

Definition at line 46 of file ap_fixed.h.

46{0};

The documentation for this struct was generated from the following file: