fixed: add to_integral, from_native

This commit is contained in:
Danny Robson 2015-01-15 13:59:28 +11:00
parent f688d8adda
commit 496991f46e
2 changed files with 24 additions and 0 deletions

View File

@ -68,6 +68,26 @@ fixed<INT, FRAC>::to_native (void) const
{ return m_value; }
//-----------------------------------------------------------------------------
template <unsigned INT, unsigned FRAC>
fixed<INT,FRAC>
fixed<INT,FRAC>::from_native (integral_type i)
{
fixed<INT,FRAC> out (integral_type {0u});
out.m_value = i;
return out;
}
//-----------------------------------------------------------------------------
template <unsigned INT, unsigned FRAC>
typename fixed<INT,FRAC>::integral_type
fixed<INT,FRAC>::to_integral (integral_type v)
{
return v >> FRAC;
}
/*
* Integral operators
*/

View File

@ -43,6 +43,10 @@ namespace util {
integral_type to_integral (void) const;
combined_type to_native (void) const;
static fixed<INT,FRAC> from_native (integral_type);
static integral_type to_integral (integral_type);
fixed<INT, FRAC>& operator +=(const fixed<INT, FRAC>);
fixed<INT, FRAC>& operator -=(const fixed<INT, FRAC>);
fixed<INT, FRAC>& operator *=(const fixed<INT, FRAC>);