X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftrunk%2FETL%2F_fixed.h;h=541f40c79ec9fe21e4d17b0a2bdaf4009518095f;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=7e8a59bf2166f8e7330a76ee7ee8e21fc5330e6f;hpb=cee5940bae97612105db8b7e1ffcf513f9d9150c;p=synfig.git diff --git a/ETL/trunk/ETL/_fixed.h b/ETL/trunk/ETL/_fixed.h index 7e8a59b..541f40c 100644 --- a/ETL/trunk/ETL/_fixed.h +++ b/ETL/trunk/ETL/_fixed.h @@ -1,9 +1,10 @@ /*! ======================================================================== ** Extended Template and Library ** Fixed-Point Math Class Implementation -** $Id: _fixed.h,v 1.1.1.1 2005/01/04 01:31:47 darco Exp $ +** $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 @@ -33,6 +34,10 @@ /* === 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::fixed_base(const _fixed &x):_data(x._data) {} template -fixed_base::fixed_base(const float &f):_data(static_cast(f*_ONE()/*+0.5f*/)) -{} +fixed_base::fixed_base(const float &f):_data(static_cast(f*_ONE() +#ifdef ROUND_TO_NEAREST_INTEGER + +0.5f +#endif + )) {} template -fixed_base::fixed_base(const double &f):_data(static_cast(f*_ONE()/*+0.5*/)) -{} +fixed_base::fixed_base(const double &f):_data(static_cast(f*_ONE() +#ifdef ROUND_TO_NEAREST_INTEGER + +0.5 +#endif + )) {} template -fixed_base::fixed_base(const long double &f):_data(static_cast(f*_ONE()/*+0.5*/)) -{} +fixed_base::fixed_base(const long double &f):_data(static_cast(f*_ONE() +#ifdef ROUND_TO_NEAREST_INTEGER + +0.5 +#endif + )) {} template fixed_base::fixed_base(const int &i):_data(i<::data()const //! fixed+=fixed template const fixed_base & -fixed_base::operator+=(const fixed_base &rhs) +fixed_base::operator+=(const _fixed &rhs) { _data+=rhs._data; return *this; @@ -253,7 +267,7 @@ fixed_base::operator+=(const fixed_base &rhs) //! fixed-=fixed template const fixed_base & -fixed_base::operator-=(const fixed_base &rhs) +fixed_base::operator-=(const _fixed &rhs) { _data-=rhs._data; return *this; @@ -261,7 +275,7 @@ fixed_base::operator-=(const fixed_base &rhs) //! fixed*=fixed template const fixed_base & -fixed_base::operator*=(const fixed_base &rhs) +fixed_base::operator*=(const _fixed &rhs) { if(_TYPE_SMALLER_THAN_INT()) _data=static_cast((int)_data*(int)rhs._data>>FIXED_BITS); @@ -276,7 +290,7 @@ fixed_base::operator*=(const fixed_base &rhs) //! fixed/=fixed template const fixed_base & -fixed_base::operator/=(const fixed_base &rhs) +fixed_base::operator/=(const _fixed &rhs) { if(_TYPE_SMALLER_THAN_INT()) _data=static_cast((int)_data/(int)rhs._data<::operator/=(const int &rhs) //! fixed + fixed template fixed_base -fixed_base::operator+(const fixed_base &rhs)const +fixed_base::operator+(const _fixed &rhs)const { _fixed ret; ret._data=_data+rhs._data; @@ -331,7 +345,7 @@ fixed_base::operator+(const fixed_base &rhs)const //! fixed - fixed template fixed_base -fixed_base::operator-(const fixed_base &rhs)const +fixed_base::operator-(const _fixed &rhs)const { _fixed ret; ret._data=_data-rhs._data; @@ -340,7 +354,7 @@ fixed_base::operator-(const fixed_base &rhs)const //! fixed * fixed template fixed_base -fixed_base::operator*(const fixed_base &rhs)const +fixed_base::operator*(const _fixed &rhs)const { _fixed ret; ret._data=((_data*rhs._data)>>FIXED_BITS); @@ -350,7 +364,7 @@ fixed_base::operator*(const fixed_base &rhs)const //! fixed / fixed template fixed_base -fixed_base::operator/(const fixed_base &rhs)const +fixed_base::operator/(const _fixed &rhs)const { _fixed ret; ret._data=((_data/rhs._data)<