projects
/
synfig.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Following the previous commit, there's no need to walk up the canvas tree to find...
[synfig.git]
/
ETL
/
trunk
/
ETL
/
_fixed.h
diff --git
a/ETL/trunk/ETL/_fixed.h
b/ETL/trunk/ETL/_fixed.h
index
7e8a59b
..
92f781e
100644
(file)
--- a/
ETL/trunk/ETL/_fixed.h
+++ b/
ETL/trunk/ETL/_fixed.h
@@
-1,7
+1,7
@@
/*! ========================================================================
** Extended Template and Library
** Fixed-Point Math Class Implementation
/*! ========================================================================
** 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) 2002 Robert B. Quattlebaum Jr.
**
@@
-33,6
+33,10
@@
/* === M A C R O S ========================================================= */
/* === 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
#ifndef ETL_FIXED_TYPE
# define ETL_FIXED_TYPE int
#endif
@@
-177,16
+181,25
@@
fixed_base<T,FIXED_BITS>::fixed_base(const _fixed &x):_data(x._data)
{}
template <class T,unsigned int FIXED_BITS>
{}
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>
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>
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)
template <class T,unsigned int FIXED_BITS>
fixed_base<T,FIXED_BITS>::fixed_base(const int &i):_data(i<<FIXED_BITS)
@@
-245,7
+258,7
@@
fixed_base<T,FIXED_BITS>::data()const
//! fixed+=fixed
template <class T,unsigned int FIXED_BITS>const fixed_base<T,FIXED_BITS> &
//! 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;
{
_data+=rhs._data;
return *this;
@@
-253,7
+266,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-=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;
{
_data-=rhs._data;
return *this;
@@
-261,7
+274,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*=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);
{
if(_TYPE_SMALLER_THAN_INT())
_data=static_cast<T>((int)_data*(int)rhs._data>>FIXED_BITS);
@@
-276,7
+289,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/=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);
{
if(_TYPE_SMALLER_THAN_INT())
_data=static_cast<T>((int)_data/(int)rhs._data<<FIXED_BITS);
@@
-322,7
+335,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 + 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 ret;
ret._data=_data+rhs._data;
@@
-331,7
+344,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 - 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 ret;
ret._data=_data-rhs._data;
@@
-340,7
+353,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 * 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);
{
_fixed ret;
ret._data=((_data*rhs._data)>>FIXED_BITS);
@@
-350,7
+363,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 / 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);
{
_fixed ret;
ret._data=((_data/rhs._data)<<FIXED_BITS);