Skip to content

Commit 5eadcba

Browse files
authored
Add integer conversion operators (#94)
Adds operators for converting to all the main integer types.
1 parent ea71949 commit 5eadcba

File tree

4 files changed

+150
-4
lines changed

4 files changed

+150
-4
lines changed

src/FixedPoints/SFixed.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,18 @@ class SFixed
9898
constexpr IntegerType getInteger() const;
9999
constexpr FractionType getFraction() const;
100100

101-
constexpr explicit operator IntegerType() const;
101+
constexpr explicit operator char() const;
102+
constexpr explicit operator unsigned char() const;
103+
constexpr explicit operator signed char() const;
104+
constexpr explicit operator unsigned short int() const;
105+
constexpr explicit operator signed short int() const;
106+
constexpr explicit operator unsigned int() const;
107+
constexpr explicit operator signed int() const;
108+
constexpr explicit operator unsigned long int() const;
109+
constexpr explicit operator signed long int() const;
110+
constexpr explicit operator unsigned long long int() const;
111+
constexpr explicit operator signed long long int() const;
112+
102113
constexpr explicit operator float() const;
103114
constexpr explicit operator double() const;
104115
constexpr explicit operator long double() const;

src/FixedPoints/SFixedMemberFunctions.h

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,73 @@ constexpr typename SFixed<Integer, Fraction>::FractionType SFixed<Integer, Fract
147147
//
148148

149149
template< unsigned Integer, unsigned Fraction >
150-
constexpr SFixed<Integer, Fraction>::operator IntegerType() const
150+
constexpr SFixed<Integer, Fraction>::operator char() const
151151
{
152152
return this->getInteger();
153153
}
154154

155+
template< unsigned Integer, unsigned Fraction >
156+
constexpr SFixed<Integer, Fraction>::operator unsigned char() const
157+
{
158+
return this->getInteger();
159+
}
160+
161+
template< unsigned Integer, unsigned Fraction >
162+
constexpr SFixed<Integer, Fraction>::operator signed char() const
163+
{
164+
return this->getInteger();
165+
}
166+
167+
template< unsigned Integer, unsigned Fraction >
168+
constexpr SFixed<Integer, Fraction>::operator unsigned short int() const
169+
{
170+
return this->getInteger();
171+
}
172+
173+
template< unsigned Integer, unsigned Fraction >
174+
constexpr SFixed<Integer, Fraction>::operator signed short int() const
175+
{
176+
return this->getInteger();
177+
}
178+
179+
template< unsigned Integer, unsigned Fraction >
180+
constexpr SFixed<Integer, Fraction>::operator unsigned int() const
181+
{
182+
return this->getInteger();
183+
}
184+
185+
template< unsigned Integer, unsigned Fraction >
186+
constexpr SFixed<Integer, Fraction>::operator signed int() const
187+
{
188+
return this->getInteger();
189+
}
190+
191+
template< unsigned Integer, unsigned Fraction >
192+
constexpr SFixed<Integer, Fraction>::operator unsigned long int() const
193+
{
194+
return this->getInteger();
195+
}
196+
197+
template< unsigned Integer, unsigned Fraction >
198+
constexpr SFixed<Integer, Fraction>::operator signed long int() const
199+
{
200+
return this->getInteger();
201+
}
202+
203+
template< unsigned Integer, unsigned Fraction >
204+
constexpr SFixed<Integer, Fraction>::operator unsigned long long int() const
205+
{
206+
return this->getInteger();
207+
}
208+
209+
template< unsigned Integer, unsigned Fraction >
210+
constexpr SFixed<Integer, Fraction>::operator signed long long int() const
211+
{
212+
return this->getInteger();
213+
}
214+
215+
216+
155217
template< unsigned Integer, unsigned Fraction >
156218
constexpr SFixed<Integer, Fraction>::operator float() const
157219
{

src/FixedPoints/UFixed.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,18 @@ class UFixed
9999
constexpr IntegerType getInteger() const;
100100
constexpr FractionType getFraction() const;
101101

102-
constexpr explicit operator IntegerType() const;
102+
constexpr explicit operator char() const;
103+
constexpr explicit operator unsigned char() const;
104+
constexpr explicit operator signed char() const;
105+
constexpr explicit operator unsigned short int() const;
106+
constexpr explicit operator signed short int() const;
107+
constexpr explicit operator unsigned int() const;
108+
constexpr explicit operator signed int() const;
109+
constexpr explicit operator unsigned long int() const;
110+
constexpr explicit operator signed long int() const;
111+
constexpr explicit operator unsigned long long int() const;
112+
constexpr explicit operator signed long long int() const;
113+
103114
constexpr explicit operator float() const;
104115
constexpr explicit operator double() const;
105116
constexpr explicit operator long double() const;

src/FixedPoints/UFixedMemberFunctions.h

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,73 @@ constexpr typename UFixed<Integer, Fraction>::FractionType UFixed<Integer, Fract
147147
//
148148

149149
template< unsigned Integer, unsigned Fraction >
150-
constexpr UFixed<Integer, Fraction>::operator IntegerType() const
150+
constexpr UFixed<Integer, Fraction>::operator char() const
151151
{
152152
return this->getInteger();
153153
}
154154

155+
template< unsigned Integer, unsigned Fraction >
156+
constexpr UFixed<Integer, Fraction>::operator unsigned char() const
157+
{
158+
return this->getInteger();
159+
}
160+
161+
template< unsigned Integer, unsigned Fraction >
162+
constexpr UFixed<Integer, Fraction>::operator signed char() const
163+
{
164+
return this->getInteger();
165+
}
166+
167+
template< unsigned Integer, unsigned Fraction >
168+
constexpr UFixed<Integer, Fraction>::operator unsigned short int() const
169+
{
170+
return this->getInteger();
171+
}
172+
173+
template< unsigned Integer, unsigned Fraction >
174+
constexpr UFixed<Integer, Fraction>::operator signed short int() const
175+
{
176+
return this->getInteger();
177+
}
178+
179+
template< unsigned Integer, unsigned Fraction >
180+
constexpr UFixed<Integer, Fraction>::operator unsigned int() const
181+
{
182+
return this->getInteger();
183+
}
184+
185+
template< unsigned Integer, unsigned Fraction >
186+
constexpr UFixed<Integer, Fraction>::operator signed int() const
187+
{
188+
return this->getInteger();
189+
}
190+
191+
template< unsigned Integer, unsigned Fraction >
192+
constexpr UFixed<Integer, Fraction>::operator unsigned long int() const
193+
{
194+
return this->getInteger();
195+
}
196+
197+
template< unsigned Integer, unsigned Fraction >
198+
constexpr UFixed<Integer, Fraction>::operator signed long int() const
199+
{
200+
return this->getInteger();
201+
}
202+
203+
template< unsigned Integer, unsigned Fraction >
204+
constexpr UFixed<Integer, Fraction>::operator unsigned long long int() const
205+
{
206+
return this->getInteger();
207+
}
208+
209+
template< unsigned Integer, unsigned Fraction >
210+
constexpr UFixed<Integer, Fraction>::operator signed long long int() const
211+
{
212+
return this->getInteger();
213+
}
214+
215+
216+
155217
template< unsigned Integer, unsigned Fraction >
156218
constexpr UFixed<Integer, Fraction>::operator float() const
157219
{

0 commit comments

Comments
 (0)