The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
floating_point_emulation::tfloat< T, S > Class Template Reference

Template class for the emulation. More...

#include <floating_point_emulation.hpp>

Public Types

enum  { shift = S }
 
enum  { factor = 1 << S }
 
typedef T value_type
 

Public Member Functions

 tfloat ()
 
 tfloat (const int value)
 
 tfloat (const double value)
 
tfloatoperator= (const tfloat rhs)
 
tfloatoperator= (const int rhs)
 
tfloatoperator= (const double rhs)
 
bool operator< (const tfloat rhs) const
 
bool operator<= (const tfloat rhs) const
 
bool operator> (const tfloat rhs) const
 
bool operator>= (const tfloat rhs) const
 
bool operator== (const tfloat rhs) const
 
bool operator== (const int rhs) const
 
bool operator== (const double rhs) const
 
bool operator!= (const tfloat rhs) const
 
bool operator!= (const int rhs) const
 
bool operator!= (const double rhs) const
 
bool operator! () const
 
tfloat operator- () const
 
tfloat operator+ () const
 
tfloatoperator*= (const tfloat rhs)
 Multiply. More...
 
tfloatoperator*= (const int rhs)
 Multiply. More...
 
tfloatoperator*= (const double rhs)
 Multiply. More...
 
tfloatoperator/= (const tfloat rhs)
 Divide. More...
 
tfloatoperator/= (const int rhs)
 Divide. More...
 
tfloatoperator/= (const double rhs)
 Divide. More...
 
tfloatoperator+= (const tfloat rhs)
 
tfloatoperator+= (const int rhs)
 
tfloatoperator+= (const double rhs)
 
tfloatoperator-= (const tfloat rhs)
 
tfloatoperator-= (const int rhs)
 
tfloatoperator-= (const double rhs)
 
int to_int () const
 
double to_double () const
 
int floor ()
 
get_value () const
 
template<>
tfloat< Sint32, 8 > & operator*= (const tfloat< Sint32, 8 > rhs)
 

Private Member Functions

tfloatnegative ()
 Changes the object to its negative value. More...
 

Private Attributes

value_
 The value of the emulation. More...
 

Friends

template<class TT , unsigned SS>
struct detail::tidiv
 

Detailed Description

template<class T, unsigned S>
class floating_point_emulation::tfloat< T, S >

Template class for the emulation.

Note
Operators that are not documented do the expected thing.
For conversions it would be nice to use the `operator int()' instead of to_int(). Unfortunately C++98 doesn't support the explicit for conversion operators and the implicit conversion is evil.
Template Parameters
TThe type used for the emulation. At the moment the following types are supported:
  • double

Definition at line 143 of file floating_point_emulation.hpp.

Member Typedef Documentation

template<class T, unsigned S>
typedef T floating_point_emulation::tfloat< T, S >::value_type

Definition at line 584 of file floating_point_emulation.hpp.

Member Enumeration Documentation

template<class T, unsigned S>
anonymous enum
Enumerator
shift 

Definition at line 586 of file floating_point_emulation.hpp.

template<class T, unsigned S>
anonymous enum
Enumerator
factor 

Definition at line 587 of file floating_point_emulation.hpp.

Constructor & Destructor Documentation

template<class T, unsigned S>
floating_point_emulation::tfloat< T, S >::tfloat ( )
inline
template<class T, unsigned S>
floating_point_emulation::tfloat< T, S >::tfloat ( const int  value)
inlineexplicit
template<class T, unsigned S>
floating_point_emulation::tfloat< T, S >::tfloat ( const double  value)
inlineexplicit

Member Function Documentation

template<class T, unsigned S>
int floating_point_emulation::tfloat< T, S >::floor ( )
inline
template<class T, unsigned S>
T floating_point_emulation::tfloat< T, S >::get_value ( ) const
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::negative ( )
inlineprivate

Changes the object to its negative value.

There is an issue with operator-(). There is an constructor that takes value_type as parameter. When shift != 0 the issue occurs. Implementing operator-() as return tfloat(-value_) returns a scaled value. Scaling twice might loose resolution and cause some overhead. So just add this function to solve the issue.

Returns
*this, but it's value is negated.

Definition at line 933 of file floating_point_emulation.hpp.

References floating_point_emulation::tfloat< T, S >::value_.

template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator! ( ) const
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator!= ( const tfloat< T, S rhs) const
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator!= ( const int  rhs) const
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator!= ( const double  rhs) const
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator*= ( const tfloat< T, S rhs)
inline

Multiply.

Keep in mind that:

THIS * RHS = this * sf * rhs * sf = result * sf * sf = RESULT * sf

Thus in order to get RESULT there needs to be divided by sf:

RESULT = THIS * RHS / sf

Definition at line 735 of file floating_point_emulation.hpp.

References FLOATING_POINT_EMULATION_RANGE_CHECK, and floating_point_emulation::tfloat< T, S >::value_.

template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator*= ( const int  rhs)
inline

Multiply.

No extra adjustment needed since:

RESULT = THIS * rhs

Definition at line 758 of file floating_point_emulation.hpp.

References FLOATING_POINT_EMULATION_RANGE_CHECK, and floating_point_emulation::tfloat< T, S >::value_.

template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator*= ( const double  rhs)
inline

Multiply.

No extra adjustment needed since:

RESULT = THIS * rhs

Definition at line 773 of file floating_point_emulation.hpp.

References FLOATING_POINT_EMULATION_RANGE_CHECK, and floating_point_emulation::tfloat< T, S >::value_.

template<>
tfloat< Sint32, 8 > & floating_point_emulation::tfloat< Sint32, 8 >::operator*= ( const tfloat< Sint32, 8 >  rhs)
inline

Specialized for the Sint32 with a shift of 8.

Instead of figuring out the optimal shift before multiplying simply multiply as a 64-bit value and then perform the shift. This is rather cheap on the Pandora and also keeps the code short on that platform (only two extra instructions on the ARM v7; a `logical shift right' instruction followed by a `logical left shifted or' instruction.)

Definition at line 988 of file floating_point_emulation.hpp.

References floating_point_emulation::tfloat< T, S >::value_.

template<class T, unsigned S>
tfloat floating_point_emulation::tfloat< T, S >::operator+ ( ) const
inline

Definition at line 713 of file floating_point_emulation.hpp.

template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator+= ( const tfloat< T, S rhs)
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator+= ( const int  rhs)
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator+= ( const double  rhs)
inline
template<class T, unsigned S>
tfloat floating_point_emulation::tfloat< T, S >::operator- ( ) const
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator-= ( const tfloat< T, S rhs)
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator-= ( const int  rhs)
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator-= ( const double  rhs)
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator/= ( const tfloat< T, S rhs)
inline

Divide.

Keep in mind that:

THIS * RHS = this * sf * rhs * sf = result * sf * sf = RESULT * sf

THIS this * sf this -— = ------— = -— = result RHS rhs * sf rhs

Thus in order to get RESULT there needs to be multiplied by sf:

     THIS

RESULT = -— * sf RHS

Definition at line 800 of file floating_point_emulation.hpp.

References floating_point_emulation::detail::tidiv< T, S >::idiv().

template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator/= ( const int  rhs)
inline

Divide.

No extra adjustment needed since:

RESULT = THIS / rhs

Definition at line 813 of file floating_point_emulation.hpp.

References FLOATING_POINT_EMULATION_RANGE_CHECK, and floating_point_emulation::tfloat< T, S >::value_.

template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator/= ( const double  rhs)
inline

Divide.

No extra adjustment needed since:

RESULT = THIS / rhs

Definition at line 828 of file floating_point_emulation.hpp.

References FLOATING_POINT_EMULATION_RANGE_CHECK, and floating_point_emulation::tfloat< T, S >::value_.

template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator< ( const tfloat< T, S rhs) const
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator<= ( const tfloat< T, S rhs) const
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator= ( const tfloat< T, S rhs)
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator= ( const int  rhs)
inline
template<class T, unsigned S>
tfloat& floating_point_emulation::tfloat< T, S >::operator= ( const double  rhs)
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator== ( const tfloat< T, S rhs) const
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator== ( const int  rhs) const
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator== ( const double  rhs) const
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator> ( const tfloat< T, S rhs) const
inline
template<class T, unsigned S>
bool floating_point_emulation::tfloat< T, S >::operator>= ( const tfloat< T, S rhs) const
inline
template<class T, unsigned S>
double floating_point_emulation::tfloat< T, S >::to_double ( ) const
inline
template<class T, unsigned S>
int floating_point_emulation::tfloat< T, S >::to_int ( ) const
inline

Friends And Related Function Documentation

template<class T, unsigned S>
template<class TT , unsigned SS>
friend struct detail::tidiv
friend

Definition at line 579 of file floating_point_emulation.hpp.

Member Data Documentation

template<class T, unsigned S>
T floating_point_emulation::tfloat< T, S >::value_
private

The documentation for this class was generated from the following file: