Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / ETL / tags / stable / ETL / _fixed.h
index 9233f21..541f40c 100644 (file)
@@ -4,6 +4,7 @@
 ** $Id$
 **
 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
+** Copyright (c) 2007 Chris Moore
 **
 ** This package is free software; you can redistribute it and/or
 ** modify it under the terms of the GNU General Public License as
 
 /* === M A C R O S ========================================================= */
 
+// the "+0.5" code was commented out - maybe to make thing run faster?
+// it can be re-enabled by uncommenting this next line:
+// #define ROUND_TO_NEAREST_INTEGER
+
 #ifndef ETL_FIXED_TYPE
 # define ETL_FIXED_TYPE        int
 #endif
@@ -177,16 +182,25 @@ fixed_base<T,FIXED_BITS>::fixed_base(const _fixed &x):_data(x._data)
 {}
 
 template <class T,unsigned int FIXED_BITS>
-fixed_base<T,FIXED_BITS>::fixed_base(const float &f):_data(static_cast<value_type>(f*_ONE()/*+0.5f*/))
-{}
+fixed_base<T,FIXED_BITS>::fixed_base(const float &f):_data(static_cast<value_type>(f*_ONE()
+#ifdef ROUND_TO_NEAREST_INTEGER
+                                                                                                                                                                  +0.5f
+#endif
+                                                                       )) {}
 
 template <class T,unsigned int FIXED_BITS>
-fixed_base<T,FIXED_BITS>::fixed_base(const double &f):_data(static_cast<value_type>(f*_ONE()/*+0.5*/))
-{}
+fixed_base<T,FIXED_BITS>::fixed_base(const double &f):_data(static_cast<value_type>(f*_ONE()
+#ifdef ROUND_TO_NEAREST_INTEGER
+                                                                                                                                                                       +0.5
+#endif
+                                                                       )) {}
 
 template <class T,unsigned int FIXED_BITS>
-fixed_base<T,FIXED_BITS>::fixed_base(const long double &f):_data(static_cast<value_type>(f*_ONE()/*+0.5*/))
-{}
+fixed_base<T,FIXED_BITS>::fixed_base(const long double &f):_data(static_cast<value_type>(f*_ONE()
+#ifdef ROUND_TO_NEAREST_INTEGER
+                                                                                                                                                                                +0.5
+#endif
+                                                                       )) {}
 
 template <class T,unsigned int FIXED_BITS>
 fixed_base<T,FIXED_BITS>::fixed_base(const int &i):_data(i<<FIXED_BITS)
@@ -245,7 +259,7 @@ fixed_base<T,FIXED_BITS>::data()const
 
 //! fixed+=fixed
 template <class T,unsigned int FIXED_BITS>const fixed_base<T,FIXED_BITS> &
-fixed_base<T,FIXED_BITS>::operator+=(const fixed_base<T,FIXED_BITS> &rhs)
+fixed_base<T,FIXED_BITS>::operator+=(const _fixed &rhs)
 {
        _data+=rhs._data;
        return *this;
@@ -253,7 +267,7 @@ fixed_base<T,FIXED_BITS>::operator+=(const fixed_base<T,FIXED_BITS> &rhs)
 
 //! fixed-=fixed
 template <class T,unsigned int FIXED_BITS>const fixed_base<T,FIXED_BITS> &
-fixed_base<T,FIXED_BITS>::operator-=(const fixed_base<T,FIXED_BITS> &rhs)
+fixed_base<T,FIXED_BITS>::operator-=(const _fixed &rhs)
 {
        _data-=rhs._data;
        return *this;
@@ -261,7 +275,7 @@ fixed_base<T,FIXED_BITS>::operator-=(const fixed_base<T,FIXED_BITS> &rhs)
 
 //! fixed*=fixed
 template <class T,unsigned int FIXED_BITS>const fixed_base<T,FIXED_BITS> &
-fixed_base<T,FIXED_BITS>::operator*=(const fixed_base<T,FIXED_BITS> &rhs)
+fixed_base<T,FIXED_BITS>::operator*=(const _fixed &rhs)
 {
        if(_TYPE_SMALLER_THAN_INT())
                _data=static_cast<T>((int)_data*(int)rhs._data>>FIXED_BITS);
@@ -276,7 +290,7 @@ fixed_base<T,FIXED_BITS>::operator*=(const fixed_base<T,FIXED_BITS> &rhs)
 
 //! fixed/=fixed
 template <class T,unsigned int FIXED_BITS>const fixed_base<T,FIXED_BITS> &
-fixed_base<T,FIXED_BITS>::operator/=(const fixed_base<T,FIXED_BITS> &rhs)
+fixed_base<T,FIXED_BITS>::operator/=(const _fixed &rhs)
 {
        if(_TYPE_SMALLER_THAN_INT())
                _data=static_cast<T>((int)_data/(int)rhs._data<<FIXED_BITS);
@@ -322,7 +336,7 @@ fixed_base<T,FIXED_BITS>::operator/=(const int &rhs)
 
 //! fixed + fixed
 template <class T,unsigned int FIXED_BITS>fixed_base<T,FIXED_BITS>
-fixed_base<T,FIXED_BITS>::operator+(const fixed_base<T,FIXED_BITS> &rhs)const
+fixed_base<T,FIXED_BITS>::operator+(const _fixed &rhs)const
 {
        _fixed ret;
        ret._data=_data+rhs._data;
@@ -331,7 +345,7 @@ fixed_base<T,FIXED_BITS>::operator+(const fixed_base<T,FIXED_BITS> &rhs)const
 
 //! fixed - fixed
 template <class T,unsigned int FIXED_BITS>fixed_base<T,FIXED_BITS>
-fixed_base<T,FIXED_BITS>::operator-(const fixed_base<T,FIXED_BITS> &rhs)const
+fixed_base<T,FIXED_BITS>::operator-(const _fixed &rhs)const
 {
        _fixed ret;
        ret._data=_data-rhs._data;
@@ -340,7 +354,7 @@ fixed_base<T,FIXED_BITS>::operator-(const fixed_base<T,FIXED_BITS> &rhs)const
 
 //! fixed * fixed
 template <class T,unsigned int FIXED_BITS>fixed_base<T,FIXED_BITS>
-fixed_base<T,FIXED_BITS>::operator*(const fixed_base<T,FIXED_BITS> &rhs)const
+fixed_base<T,FIXED_BITS>::operator*(const _fixed &rhs)const
 {
        _fixed ret;
        ret._data=((_data*rhs._data)>>FIXED_BITS);
@@ -350,7 +364,7 @@ fixed_base<T,FIXED_BITS>::operator*(const fixed_base<T,FIXED_BITS> &rhs)const
 
 //! fixed / fixed
 template <class T,unsigned int FIXED_BITS>fixed_base<T,FIXED_BITS>
-fixed_base<T,FIXED_BITS>::operator/(const fixed_base<T,FIXED_BITS> &rhs)const
+fixed_base<T,FIXED_BITS>::operator/(const _fixed &rhs)const
 {
        _fixed ret;
        ret._data=((_data/rhs._data)<<FIXED_BITS);