"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSMathLib/Src/Fixed/LSMFixed.h

00001 
00016 #ifndef __LSM_FIXED_H__
00017 #define __LSM_FIXED_H__
00018 
00019 #include "LSSTDStandardLib.h"
00020 using namespace ::lsstd;
00021 
00022 #include <cassert>
00023 
00024 
00025 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00026 // MACROS
00027 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00031 #define LSM_FIXED_ROUNDING
00032 
00033 namespace lsm {
00034 
00040         template <typename _tType, unsigned _uBits = 12>
00041         class CFixed {
00042         public :
00043                 // This class allows us to define a type that is not meant to be modified
00044                 //      when passed to the constructor of CFixed.
00045                 class CFixedRawType {
00046                 public :
00047                         LSE_CALLCTOR                                            CFixedRawType( _tType _tVal ) :
00048                                 m_tValue( _tVal ) {}
00049 
00050                         _tType                                                          m_tValue;
00051                 };
00052 
00053                 // == Various constructors.
00054                 LSE_CALLCTOR                                                    CFixed() {
00055                 }
00056                 LSE_CALLCTOR                                                    CFixed( const CFixedRawType &_frtRaw ) :
00057                         m_tValue( _frtRaw.m_tValue ) {
00058                 }
00059                 LSE_CALLCTOR                                                    CFixed( const CFixed<_tType, _uBits> &_tVal ) :
00060                         m_tValue( _tVal.m_tValue ) {
00061                 }
00062                 LSE_CALLCTOR                                                    CFixed( LSINT8 _i8Val ) :
00063                         m_tValue( static_cast<_tType>(_i8Val) << _uBits ) {
00064                 }
00065                 LSE_CALLCTOR                                                    CFixed( LSUINT8 _ui8Val ) :
00066                         m_tValue( static_cast<_tType>(_ui8Val) << _uBits ) {
00067                 }
00068                 LSE_CALLCTOR                                                    CFixed( LSINT16 _i16Val ) :
00069                         m_tValue( static_cast<_tType>(_i16Val) << _uBits ) {
00070                 }
00071                 LSE_CALLCTOR                                                    CFixed( LSUINT16 _ui16Val ) :
00072                         m_tValue( static_cast<_tType>(_ui16Val) << _uBits ) {
00073                 }
00074                 LSE_CALLCTOR                                                    CFixed( LSINT32 _i32Val ) :
00075                         m_tValue( static_cast<_tType>(_i32Val) << _uBits ) {
00076                 }
00077                 LSE_CALLCTOR                                                    CFixed( LSUINT32 _ui32Val ) :
00078                         m_tValue( static_cast<_tType>(_ui32Val) << _uBits ) {
00079                 }
00080                 LSE_CALLCTOR                                                    CFixed( LSINT64 _i64Val ) :
00081                         m_tValue( static_cast<_tType>(_i64Val << _uBits) ) {
00082                 }
00083                 LSE_CALLCTOR                                                    CFixed( LSUINT64 _ui64Val ) :
00084                         m_tValue( static_cast<_tType>(_ui64Val << _uBits) ) {
00085                 }
00086                 LSE_CALLCTOR                                                    CFixed( LSFLOAT _fVal ) :
00087                         m_tValue( static_cast<_tType>(_fVal * (static_cast<_tType>(1UL) << _uBits)) ) {
00088                 }
00089                 LSE_CALLCTOR                                                    CFixed( LSDOUBLE _dVal ) :
00090                         m_tValue( static_cast<_tType>(_dVal * (static_cast<_tType>(1UL) << _uBits)) ) {
00091                 }
00092 
00093                 // == Functions.
00099                 static LSE_INLINE _tType LSE_FCALL              Bits()          { return _uBits; }
00100 
00106                 static LSE_INLINE _tType LSE_FCALL              One()           { return (static_cast<_tType>(1) << _uBits); }
00107 
00113                 static LSE_INLINE _tType LSE_FCALL              SignMask()      {
00114                         return static_cast<_tType>(1) << (sizeof( _tType ) * 8 - 1);
00115                 }
00116 
00122                 static LSE_INLINE _tType LSE_FCALL              DigitMask()     { return ~SignMask(); }
00123 
00129                 static LSE_INLINE LSFLOAT LSE_FCALL             RecFloat()      { return 1.0f / One(); }
00130 
00136                 static LSE_INLINE LSDOUBLE LSE_FCALL    RecDouble()     { return 1.0 / One(); }
00137 
00145                 static LSE_INLINE _tType LSE_FCALL              Cast( LSINT8 _i8Val )   { return static_cast<_tType>(_i8Val); }
00146 
00154                 static LSE_INLINE _tType LSE_FCALL              Cast( LSUINT8 _ui8Val ) { return static_cast<_tType>(_ui8Val); }
00155 
00163                 static LSE_INLINE _tType LSE_FCALL              Cast( LSINT16 _i16Val ) { return static_cast<_tType>(_i16Val); }
00164 
00172                 static LSE_INLINE _tType LSE_FCALL              Cast( LSUINT16 _ui16Val )       { return static_cast<_tType>(_ui16Val); }
00173 
00181                 static LSE_INLINE _tType LSE_FCALL              Cast( LSINT32 _i32Val ) { return static_cast<_tType>(_i32Val); }
00182 
00190                 static LSE_INLINE _tType LSE_FCALL              Cast( LSUINT32 _ui32Val )       { return static_cast<_tType>(_ui32Val); }
00191 
00199                 static LSE_INLINE _tType LSE_FCALL              Cast( LSINT64 _i64Val ) { return static_cast<_tType>(_i64Val); }
00200 
00208                 static LSE_INLINE _tType LSE_FCALL              Cast( LSUINT64 _ui64Val )       { return static_cast<_tType>(_ui64Val); }
00209 
00217                 static LSE_INLINE _tType LSE_FCALL              Cast( LSFLOAT _fVal )           { return static_cast<_tType>(_fVal); }
00218 
00226                 static LSE_INLINE _tType LSE_FCALL              Cast( LSDOUBLE _dVal )          { return static_cast<_tType>(_dVal); }
00227                 
00228 
00229                 // == Operators.
00236                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( const CFixed<_tType, _uBits> &_tVal ) {
00237                         m_tValue = _tVal.m_tValue;
00238                         return (*this);
00239                 }
00240 
00247                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSINT8 _i8Val ) {
00248                         m_tValue = static_cast<_tType>(_i8Val) << _uBits;
00249                         return (*this);
00250                 }
00251 
00258                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSUINT8 _ui8Val ) {
00259                         m_tValue = static_cast<_tType>(_ui8Val) << _uBits;
00260                         return (*this);
00261                 }
00262 
00269                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSINT16 _i16Val ) {
00270                         m_tValue = static_cast<_tType>(_i16Val) << _uBits;
00271                         return (*this);
00272                 }
00273 
00280                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSUINT16 _ui16Val ) {
00281                         m_tValue = static_cast<_tType>(_ui16Val) << _uBits;
00282                         return (*this);
00283                 }
00284 
00291                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSINT32 _i32Val ) {
00292                         m_tValue = static_cast<_tType>(_i32Val) << _uBits;
00293                         return (*this);
00294                 }
00295 
00302                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSUINT32 _ui32Val ) {
00303                         m_tValue = static_cast<_tType>(_ui32Val) << _uBits;
00304                         return (*this);
00305                 }
00306 
00313                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSINT64 _i64Val ) {
00314                         m_tValue = _i64Val << _uBits;
00315                         return (*this);
00316                 }
00317 
00324                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSUINT64 _ui64Val ) {
00325                         m_tValue = _ui64Val << _uBits;
00326                         return (*this);
00327                 }
00328 
00335                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSFLOAT _fVal ) {
00336                         m_tValue = static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
00337                         return (*this);
00338                 }
00339 
00346                 LSE_INLINE CFixed & LSE_FCALL                   operator = ( LSDOUBLE _dVal ) {
00347                         m_tValue += static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
00348                         return (*this);
00349                 }
00350 
00357                 LSE_INLINE CFixed LSE_FCALL                             operator + ( const CFixed<_tType, _uBits> &_tVal ) const {
00358                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + _tVal.m_tValue ) );
00359                 }
00360 
00367                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSINT8 _i8Val ) const {
00368                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + (static_cast<_tType>(_i8Val) << _uBits) ) );
00369                 }
00370 
00377                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSUINT8 _ui8Val ) const {
00378                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + (static_cast<_tType>(_ui8Val) << _uBits) ) );
00379                 }
00380 
00387                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSINT16 _i16Val ) const {
00388                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + (static_cast<_tType>(_i16Val) << _uBits) ) );
00389                 }
00390 
00397                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSUINT16 _ui16Val ) const {
00398                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + (static_cast<_tType>(_ui16Val) << _uBits) ) );
00399                 }
00400 
00407                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSINT32 _i32Val ) const {
00408                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + (static_cast<_tType>(_i32Val) << _uBits) ) );
00409                 }
00410 
00417                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSUINT32 _ui32Val ) const {
00418                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + (static_cast<_tType>(_ui32Val) << _uBits) ) );
00419                 }
00420 
00427                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSINT64 _i64Val ) const {
00428                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + (_i64Val << _uBits) ) );
00429                 }
00430 
00437                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSUINT64 _ui64Val ) const {
00438                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + (_ui64Val << _uBits) ) );
00439                 }
00440 
00447                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSFLOAT _fVal ) const {
00448                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits)) ) );
00449                 }
00450 
00457                 LSE_INLINE CFixed LSE_FCALL                             operator + ( LSDOUBLE _dVal ) const {
00458                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue + static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits)) ) );
00459                 }
00460 
00467                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( const CFixed<_tType, _uBits> &_tVal ) {
00468                         m_tValue += _tVal.m_tValue;
00469                         return (*this);
00470                 }
00471 
00478                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSINT8 _i8Val ) {
00479                         m_tValue += (static_cast<_tType>(_i8Val) << _uBits);
00480                         return (*this);
00481                 }
00482 
00489                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSUINT8 _ui8Val ) {
00490                         m_tValue += (static_cast<_tType>(_ui8Val) << _uBits);
00491                         return (*this);
00492                 }
00493 
00500                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSINT16 _i16Val ) {
00501                         m_tValue += (static_cast<_tType>(_i16Val) << _uBits);
00502                         return (*this);
00503                 }
00504 
00511                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSUINT16 _ui16Val ) {
00512                         m_tValue += (static_cast<_tType>(_ui16Val) << _uBits);
00513                         return (*this);
00514                 }
00515 
00522                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSINT32 _i32Val ) {
00523                         m_tValue += (static_cast<_tType>(_i32Val) << _uBits);
00524                         return (*this);
00525                 }
00526 
00533                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSUINT32 _ui32Val ) {
00534                         m_tValue += (static_cast<_tType>(_ui32Val) << _uBits);
00535                         return (*this);
00536                 }
00537 
00544                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSINT64 _i64Val ) {
00545                         m_tValue += (_i64Val << _uBits);
00546                         return (*this);
00547                 }
00548 
00555                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSUINT64 _ui64Val ) {
00556                         m_tValue += (_ui64Val << _uBits);
00557                         return (*this);
00558                 }
00559 
00566                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSFLOAT _fVal ) {
00567                         m_tValue += static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
00568                         return (*this);
00569                 }
00570 
00577                 LSE_INLINE CFixed & LSE_FCALL                   operator += ( LSDOUBLE _dVal ) {
00578                         m_tValue += static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
00579                         return (*this);
00580                 }
00581 
00588                 LSE_INLINE CFixed LSE_FCALL                             operator - ( const CFixed<_tType, _uBits> &_tVal ) const {
00589                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - _tVal.m_tValue ) );
00590                 }
00591 
00598                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSINT8 _i8Val ) const {
00599                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - (static_cast<_tType>(_i8Val) << _uBits) ) );
00600                 }
00601 
00608                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSUINT8 _ui8Val ) const {
00609                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - (static_cast<_tType>(_ui8Val) << _uBits) ) );
00610                 }
00611 
00618                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSINT16 _i16Val ) const {
00619                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - (static_cast<_tType>(_i16Val) << _uBits) ) );
00620                 }
00621 
00628                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSUINT16 _ui16Val ) const {
00629                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - (static_cast<_tType>(_ui16Val) << _uBits) ) );
00630                 }
00631 
00638                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSINT32 _i32Val ) const {
00639                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - (static_cast<_tType>(_i32Val) << _uBits) ) );
00640                 }
00641 
00648                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSUINT32 _ui32Val ) const {
00649                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - (static_cast<_tType>(_ui32Val) << _uBits) ) );
00650                 }
00651 
00658                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSINT64 _i64Val ) const {
00659                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - (_i64Val << _uBits) ) );
00660                 }
00661 
00668                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSUINT64 _ui64Val ) const {
00669                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - (_ui64Val << _uBits) ) );
00670                 }
00671 
00678                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSFLOAT _fVal ) const {
00679                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits)) ) );
00680                 }
00681 
00688                 LSE_INLINE CFixed LSE_FCALL                             operator - ( LSDOUBLE _dVal ) const {
00689                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue - static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits)) ) );
00690                 }
00691 
00698                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( const CFixed<_tType, _uBits> &_tVal ) {
00699                         m_tValue -= _tVal.m_tValue;
00700                         return (*this);
00701                 }
00702 
00709                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSINT8 _i8Val ) {
00710                         m_tValue -= (static_cast<_tType>(_i8Val) << _uBits);
00711                         return (*this);
00712                 }
00713 
00720                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSUINT8 _ui8Val ) {
00721                         m_tValue -= (static_cast<_tType>(_ui8Val) << _uBits);
00722                         return (*this);
00723                 }
00724                 
00725                 
00732                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSINT16 _i16Val ) {
00733                         m_tValue -= (static_cast<_tType>(_i16Val) << _uBits);
00734                         return (*this);
00735                 }
00736 
00743                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSUINT16 _ui16Val ) {
00744                         m_tValue -= (static_cast<_tType>(_ui16Val) << _uBits);
00745                         return (*this);
00746                 }
00747 
00754                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSINT32 _i32Val ) {
00755                         m_tValue -= (static_cast<_tType>(_i32Val) << _uBits);
00756                         return (*this);
00757                 }
00758 
00765                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSUINT32 _ui32Val ) {
00766                         m_tValue -= (static_cast<_tType>(_ui32Val) << _uBits);
00767                         return (*this);
00768                 }
00769 
00776                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSINT64 _i64Val ) {
00777                         m_tValue -= (_i64Val << _uBits);
00778                         return (*this);
00779                 }
00780 
00787                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSUINT64 _ui64Val ) {
00788                         m_tValue -= (_ui64Val << _uBits);
00789                         return (*this);
00790                 }
00791 
00798                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSFLOAT _fVal ) {
00799                         m_tValue -= static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
00800                         return (*this);
00801                 }
00802 
00809                 LSE_INLINE CFixed & LSE_FCALL                   operator -= ( LSDOUBLE _dVal ) {
00810                         m_tValue -= static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
00811                         return (*this);
00812                 }
00813 
00820                 LSE_INLINE CFixed LSE_FCALL                             operator * ( const CFixed<_tType, _uBits> &_tVal ) const {
00821                         register LSINT64 i64Interm = (static_cast<LSINT64>(m_tValue) * _tVal.m_tValue);
00822                         i64Interm += i64Interm & (1LL << (_uBits - 1));
00823 #ifdef _DEBUG
00824                         LSUINT32 ui32Final = HighestBit( i64Interm );
00825                         if ( ui32Final >= (sizeof( _tType ) * 8UL) + _uBits ) {
00826                                 assert( 0 );
00827                         }
00828 #endif  // #ifdef _DEBUG
00829                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>(i64Interm >> _uBits) ) );
00830                 }
00831 
00838                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSINT8 _i8Val ) const {
00839                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue * _i8Val ) );
00840                 }
00841 
00848                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSUINT8 _ui8Val ) const {
00849                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue * _ui8Val ) );
00850                 }
00851 
00858                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSINT16 _i16Val ) const {
00859                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue * _i16Val ) );
00860                 }
00861 
00868                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSUINT16 _ui16Val ) const {
00869                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue * _ui16Val ) );
00870                 }
00871 
00878                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSINT32 _i32Val ) const {
00879                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue * _i32Val ) );
00880                 }
00881 
00888                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSUINT32 _ui32Val ) const {
00889                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue * _ui32Val ) );
00890                 }
00891 
00898                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSINT64 _i64Val ) const {
00899                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue * _i64Val ) );
00900                 }
00901 
00908                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSUINT64 _ui64Val ) const {
00909                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>(m_tValue * _ui64Val) ) );
00910                 }
00911 
00918                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSFLOAT _fVal ) const {
00919                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>(m_tValue * _fVal) ) );
00920                 }
00921 
00928                 LSE_INLINE CFixed LSE_FCALL                             operator * ( LSDOUBLE _dVal ) const {
00929                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>(m_tValue * _dVal) ) );
00930                 }
00931 
00938                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( const CFixed<_tType, _uBits> &_tVal ) {
00939                         register LSINT64 i64Interm = (static_cast<LSINT64>(m_tValue) * _tVal.m_tValue);
00940                         i64Interm += i64Interm & (1LL << (_uBits - 1));
00941 #ifdef _DEBUG
00942                         LSUINT32 ui32Final = HighestBit( i64Interm );
00943                         if ( ui32Final >= (sizeof( _tType ) * 8UL) + _uBits ) {
00944                                 assert( 0 );
00945                         }
00946 #endif  // #ifdef _DEBUG
00947                         m_tValue = static_cast<_tType>(i64Interm >> _uBits);
00948                         return (*this);
00949                 }
00950 
00957                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSINT8 _i8Val ) {
00958                         m_tValue = m_tValue * _i8Val;
00959                         return (*this);
00960                 }
00961 
00968                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSUINT8 _ui8Val ) {
00969                         m_tValue = m_tValue * _ui8Val;
00970                         return (*this);
00971                 }
00972 
00979                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSINT16 _i16Val ) {
00980                         m_tValue = m_tValue * _i16Val;
00981                         return (*this);
00982                 }
00983 
00990                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSUINT16 _ui16Val ) {
00991                         m_tValue = m_tValue * _ui16Val;
00992                         return (*this);
00993                 }
00994 
01001                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSINT32 _i32Val ) {
01002                         m_tValue = m_tValue * _i32Val;
01003                         return (*this);
01004                 }
01005 
01012                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSUINT32 _ui32Val ) {
01013                         m_tValue = m_tValue * _ui32Val;
01014                         return (*this);
01015                 }
01016 
01023                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSINT64 _i64Val ) {
01024                         m_tValue = m_tValue * _i64Val;
01025                         return (*this);
01026                 }
01027 
01034                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSUINT64 _ui64Val ) {
01035                         m_tValue = static_cast<_tType>(m_tValue * _ui64Val);
01036                         return (*this);
01037                 }
01038 
01045                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSFLOAT _fVal ) {
01046                         m_tValue = static_cast<_tType>(m_tValue * _fVal);
01047                         return (*this);
01048                 }
01049 
01056                 LSE_INLINE CFixed & LSE_FCALL                   operator *= ( LSDOUBLE _dVal ) {
01057                         m_tValue = static_cast<_tType>(m_tValue * _dVal);
01058                         return (*this);
01059                 }
01060 
01067                 LSE_INLINE CFixed LSE_FCALL                             operator / ( const CFixed<_tType, _uBits> &_tVal ) const {
01068 #ifdef LSM_FIXED_ROUNDING
01069                         register LSINT64 i64Interm = (static_cast<LSINT64>(m_tValue) << (_uBits + 1UL));
01070                         i64Interm /= _tVal.m_tValue;
01071                         // If the bottom bit is set, add 1 to the final result.
01072                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>((i64Interm >> 1) + (i64Interm & 1)) ) );
01073 #else
01074                         register LSINT64 i64Interm = (static_cast<LSINT64>(m_tValue) << _uBits);
01075                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>(i64Interm / _tVal.m_tValue) ) );
01076 #endif  // #ifdef LSM_FIXED_ROUNDING
01077                 }
01078 
01085                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSINT8 _i8Val ) const {
01086                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue / _i8Val ) );
01087                 }
01088 
01095                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSUINT8 _ui8Val ) const {
01096                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue / _ui8Val ) );
01097                 }
01098 
01105                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSINT16 _i16Val ) const {
01106                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue / _i16Val ) );
01107                 }
01108 
01115                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSUINT16 _ui16Val ) const {
01116                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue / _ui16Val ) );
01117                 }
01118 
01125                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSINT32 _i32Val ) const {
01126                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue / _i32Val ) );
01127                 }
01128 
01135                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSUINT32 _ui32Val ) const {
01136                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue / _ui32Val ) );
01137                 }
01138 
01145                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSINT64 _i64Val ) const {
01146                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue / _i64Val ) );
01147                 }
01148 
01155                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSUINT64 _ui64Val ) const {
01156                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>(m_tValue / _ui64Val) ) );
01157                 }
01158 
01165                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSFLOAT _fVal ) const {
01166                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>(m_tValue / _fVal) ) );
01167                 }
01168 
01175                 LSE_INLINE CFixed LSE_FCALL                             operator / ( LSDOUBLE _dVal ) const {
01176                         return CFixed<_tType, _uBits>( CFixedRawType( static_cast<_tType>(m_tValue / _dVal) ) );
01177                 }
01178 
01185                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( const CFixed<_tType, _uBits> &_tVal ) {
01186 #ifdef LSM_FIXED_ROUNDING
01187                         register LSINT64 i64Interm = (static_cast<LSINT64>(m_tValue) << (_uBits + 1UL));
01188                         i64Interm /= _tVal.m_tValue;
01189                         // If the bottom bit is set, add 1 to the final result.
01190                         m_tValue = static_cast<_tType>((i64Interm >> 1) + (i64Interm & 1));
01191 #else
01192                         register LSINT64 i64Interm = (static_cast<LSINT64>(m_tValue) << _uBits);
01193                         m_tValue = static_cast<_tType>(i64Interm / _tVal.m_tValue);
01194 #endif  // #ifdef LSM_FIXED_ROUNDING
01195                         return (*this);
01196                 }
01197 
01204                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSINT8 _i8Val ) {
01205                         m_tValue = m_tValue / _i8Val;
01206                         return (*this);
01207                 }
01208 
01215                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSUINT8 _ui8Val ) {
01216                         m_tValue = m_tValue / _ui8Val;
01217                         return (*this);
01218                 }
01219 
01226                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSINT16 _i16Val ) {
01227                         m_tValue = m_tValue / _i16Val;
01228                         return (*this);
01229                 }
01230 
01237                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSUINT16 _ui16Val ) {
01238                         m_tValue = m_tValue / _ui16Val;
01239                         return (*this);
01240                 }
01241 
01248                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSINT32 _i32Val ) {
01249                         m_tValue = m_tValue / _i32Val;
01250                         return (*this);
01251                 }
01252 
01259                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSUINT32 _ui32Val ) {
01260                         m_tValue = m_tValue / _ui32Val;
01261                         return (*this);
01262                 }
01263 
01270                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSINT64 _i64Val ) {
01271                         m_tValue = m_tValue / _i64Val;
01272                         return (*this);
01273                 }
01274 
01281                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSUINT64 _ui64Val ) {
01282                         m_tValue = static_cast<_tType>(m_tValue / _ui64Val);
01283                         return (*this);
01284                 }
01285 
01292                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSFLOAT _fVal ) {
01293                         m_tValue /= _fVal;
01294                         return (*this);
01295                 }
01296 
01303                 LSE_INLINE CFixed & LSE_FCALL                   operator /= ( LSDOUBLE _dVal ) {
01304                         m_tValue /= _dVal;
01305                         return (*this);
01306                 }
01307 
01308 
01309                 // Modulus.
01310                 /*LSE_INLINE CFixed LSE_FCALL                           operator % ( const CFixed<_tType, _uBits> &_tVal ) const {
01311                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue % _tVal.m_tValue ) );
01312                 }
01313                 LSE_INLINE CFixed LSE_FCALL                             operator % ( const _tType &_tVal ) const {
01314                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue % (_tVal << _uBits) ) );
01315                 }*/
01316 
01322                 LSE_INLINE CFixed LSE_FCALL                             operator - () const {
01323                         return CFixed<_tType, _uBits>( CFixedRawType( -m_tValue ) );
01324                 }
01325 
01331                 LSE_INLINE CFixed LSE_FCALL                             operator + () const {
01332                         return CFixed<_tType, _uBits>( CFixedRawType( m_tValue ) );
01333                 }
01334 
01341                 LSE_INLINE bool LSE_FCALL                               operator == ( const CFixed<_tType, _uBits> &_tVal ) const {
01342                         return m_tValue == _tVal.m_tValue;
01343                 }
01344 
01351                 LSE_INLINE bool LSE_FCALL                               operator == ( LSINT8 _i8Val ) const {
01352                         return m_tValue == (static_cast<_tType>(_i8Val) << _uBits);
01353                 }
01354 
01361                 LSE_INLINE bool LSE_FCALL                               operator == ( LSUINT8 _ui8Val ) const {
01362                         return m_tValue == (static_cast<_tType>(_ui8Val) << _uBits);
01363                 }
01364 
01371                 LSE_INLINE bool LSE_FCALL                               operator == ( LSINT16 _i16Val ) const {
01372                         return m_tValue == (static_cast<_tType>(_i16Val) << _uBits);
01373                 }
01374 
01381                 LSE_INLINE bool LSE_FCALL                               operator == ( LSUINT16 _ui16Val ) const {
01382                         return m_tValue == (static_cast<_tType>(_ui16Val) << _uBits);
01383                 }
01384 
01391                 LSE_INLINE bool LSE_FCALL                               operator == ( LSINT32 _i32Val ) const {
01392                         return m_tValue == (static_cast<_tType>(_i32Val) << _uBits);
01393                 }
01394 
01401                 LSE_INLINE bool LSE_FCALL                               operator == ( LSUINT32 _ui32Val ) const {
01402                         return m_tValue == (static_cast<_tType>(_ui32Val) << _uBits);
01403                 }
01404 
01411                 LSE_INLINE bool LSE_FCALL                               operator == ( LSINT64 _i64Val ) const {
01412                         return m_tValue == (_i64Val << _uBits);
01413                 }
01414 
01421                 LSE_INLINE bool LSE_FCALL                               operator == ( LSUINT64 _ui64Val ) const {
01422                         return m_tValue == (_ui64Val << _uBits);
01423                 }
01424 
01431                 LSE_INLINE bool LSE_FCALL                               operator == ( LSFLOAT _fVal ) const {
01432                         return m_tValue == static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
01433                 }
01434 
01441                 LSE_INLINE bool LSE_FCALL                               operator == ( LSDOUBLE _dVal ) const {
01442                         return m_tValue == static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
01443                 }
01444 
01451                 LSE_INLINE bool LSE_FCALL                               operator != ( const CFixed<_tType, _uBits> &_tVal ) const {
01452                         return m_tValue != _tVal.m_tValue;
01453                 }
01454 
01461                 LSE_INLINE bool LSE_FCALL                               operator != ( LSINT8 _i8Val ) const {
01462                         return m_tValue != (static_cast<_tType>(_i8Val) << _uBits);
01463                 }
01464 
01471                 LSE_INLINE bool LSE_FCALL                               operator != ( LSUINT8 _ui8Val ) const {
01472                         return m_tValue != (static_cast<_tType>(_ui8Val) << _uBits);
01473                 }
01474 
01481                 LSE_INLINE bool LSE_FCALL                               operator != ( LSINT16 _i16Val ) const {
01482                         return m_tValue != (static_cast<_tType>(_i16Val) << _uBits);
01483                 }
01484 
01491                 LSE_INLINE bool LSE_FCALL                               operator != ( LSUINT16 _ui16Val ) const {
01492                         return m_tValue != (static_cast<_tType>(_ui16Val) << _uBits);
01493                 }
01494 
01501                 LSE_INLINE bool LSE_FCALL                               operator != ( LSINT32 _i32Val ) const {
01502                         return m_tValue != (static_cast<_tType>(_i32Val) << _uBits);
01503                 }
01504 
01511                 LSE_INLINE bool LSE_FCALL                               operator != ( LSUINT32 _ui32Val ) const {
01512                         return m_tValue != (static_cast<_tType>(_ui32Val) << _uBits);
01513                 }
01514 
01521                 LSE_INLINE bool LSE_FCALL                               operator != ( LSINT64 _i64Val ) const {
01522                         return m_tValue != (_i64Val << _uBits);
01523                 }
01524 
01531                 LSE_INLINE bool LSE_FCALL                               operator != ( LSUINT64 _ui64Val ) const {
01532                         return m_tValue != (_ui64Val << _uBits);
01533                 }
01534 
01541                 LSE_INLINE bool LSE_FCALL                               operator != ( LSFLOAT _fVal ) const {
01542                         return m_tValue != static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
01543                 }
01544 
01551                 LSE_INLINE bool LSE_FCALL                               operator != ( LSDOUBLE _dVal ) const {
01552                         return m_tValue != static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
01553                 }
01554 
01561                 LSE_INLINE bool LSE_FCALL                               operator > ( const CFixed<_tType, _uBits> &_tVal ) const {
01562                         return m_tValue > _tVal.m_tValue;
01563                 }
01564 
01571                 LSE_INLINE bool LSE_FCALL                               operator > ( LSINT8 _i8Val ) const {
01572                         return m_tValue > (static_cast<_tType>(_i8Val) << _uBits);
01573                 }
01574 
01581                 LSE_INLINE bool LSE_FCALL                               operator > ( LSUINT8 _ui8Val ) const {
01582                         return m_tValue > (static_cast<_tType>(_ui8Val) << _uBits);
01583                 }
01584 
01591                 LSE_INLINE bool LSE_FCALL                               operator > ( LSINT16 _i16Val ) const {
01592                         return m_tValue > (static_cast<_tType>(_i16Val) << _uBits);
01593                 }
01594 
01601                 LSE_INLINE bool LSE_FCALL                               operator > ( LSUINT16 _ui16Val ) const {
01602                         return m_tValue > (static_cast<_tType>(_ui16Val) << _uBits);
01603                 }
01604 
01611                 LSE_INLINE bool LSE_FCALL                               operator > ( LSINT32 _i32Val ) const {
01612                         return m_tValue > (static_cast<_tType>(_i32Val) << _uBits);
01613                 }
01614 
01621                 LSE_INLINE bool LSE_FCALL                               operator > ( LSUINT32 _ui32Val ) const {
01622                         return m_tValue > (static_cast<_tType>(_ui32Val) << _uBits);
01623                 }
01624 
01631                 LSE_INLINE bool LSE_FCALL                               operator > ( LSINT64 _i64Val ) const {
01632                         return m_tValue > (_i64Val << _uBits);
01633                 }
01634 
01641                 LSE_INLINE bool LSE_FCALL                               operator > ( LSUINT64 _ui64Val ) const {
01642                         return m_tValue > (_ui64Val << _uBits);
01643                 }
01644 
01651                 LSE_INLINE bool LSE_FCALL                               operator > ( LSFLOAT _fVal ) const {
01652                         return m_tValue > static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
01653                 }
01654 
01661                 LSE_INLINE bool LSE_FCALL                               operator > ( LSDOUBLE _dVal ) const {
01662                         return m_tValue > static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
01663                 }
01664 
01671                 LSE_INLINE bool LSE_FCALL                               operator >= ( const CFixed<_tType, _uBits> &_tVal ) const {
01672                         return m_tValue >= _tVal.m_tValue;
01673                 }
01674 
01681                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSINT8 _i8Val ) const {
01682                         return m_tValue >= (static_cast<_tType>(_i8Val) << _uBits);
01683                 }
01684 
01691                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSUINT8 _ui8Val ) const {
01692                         return m_tValue >= (static_cast<_tType>(_ui8Val) << _uBits);
01693                 }
01694 
01701                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSINT16 _i16Val ) const {
01702                         return m_tValue >= (static_cast<_tType>(_i16Val) << _uBits);
01703                 }
01704 
01711                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSUINT16 _ui16Val ) const {
01712                         return m_tValue >= (static_cast<_tType>(_ui16Val) << _uBits);
01713                 }
01714 
01721                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSINT32 _i32Val ) const {
01722                         return m_tValue >= (static_cast<_tType>(_i32Val) << _uBits);
01723                 }
01724 
01731                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSUINT32 _ui32Val ) const {
01732                         return m_tValue >= (static_cast<_tType>(_ui32Val) << _uBits);
01733                 }
01734 
01741                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSINT64 _i64Val ) const {
01742                         return m_tValue >= (_i64Val << _uBits);
01743                 }
01744 
01751                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSUINT64 _ui64Val ) const {
01752                         return m_tValue >= (_ui64Val << _uBits);
01753                 }
01754 
01761                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSFLOAT _fVal ) const {
01762                         return m_tValue >= static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
01763                 }
01764 
01771                 LSE_INLINE bool LSE_FCALL                               operator >= ( LSDOUBLE _dVal ) const {
01772                         return m_tValue >= static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
01773                 }
01774 
01781                 LSE_INLINE bool LSE_FCALL                               operator < ( const CFixed<_tType, _uBits> &_tVal ) const {
01782                         return m_tValue < _tVal.m_tValue;
01783                 }
01784 
01791                 LSE_INLINE bool LSE_FCALL                               operator < ( LSINT8 _i8Val ) const {
01792                         return m_tValue < (static_cast<_tType>(_i8Val) << _uBits);
01793                 }
01794 
01801                 LSE_INLINE bool LSE_FCALL                               operator < ( LSUINT8 _ui8Val ) const {
01802                         return m_tValue < (static_cast<_tType>(_ui8Val) << _uBits);
01803                 }
01804 
01811                 LSE_INLINE bool LSE_FCALL                               operator < ( LSINT16 _i16Val ) const {
01812                         return m_tValue < (static_cast<_tType>(_i16Val) << _uBits);
01813                 }
01814 
01821                 LSE_INLINE bool LSE_FCALL                               operator < ( LSUINT16 _ui16Val ) const {
01822                         return m_tValue < (static_cast<_tType>(_ui16Val) << _uBits);
01823                 }
01824 
01831                 LSE_INLINE bool LSE_FCALL                               operator < ( LSINT32 _i32Val ) const {
01832                         return m_tValue < (static_cast<_tType>(_i32Val) << _uBits);
01833                 }
01834 
01841                 LSE_INLINE bool LSE_FCALL                               operator < ( LSUINT32 _ui32Val ) const {
01842                         return m_tValue < (static_cast<_tType>(_ui32Val) << _uBits);
01843                 }
01844 
01851                 LSE_INLINE bool LSE_FCALL                               operator < ( LSINT64 _i64Val ) const {
01852                         return m_tValue < (_i64Val << _uBits);
01853                 }
01854 
01861                 LSE_INLINE bool LSE_FCALL                               operator < ( LSUINT64 _ui64Val ) const {
01862                         return m_tValue < (_ui64Val << _uBits);
01863                 }
01864 
01871                 LSE_INLINE bool LSE_FCALL                               operator < ( LSFLOAT _fVal ) const {
01872                         return m_tValue < static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
01873                 }
01874 
01881                 LSE_INLINE bool LSE_FCALL                               operator < ( LSDOUBLE _dVal ) const {
01882                         return m_tValue < static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
01883                 }
01884 
01891                 LSE_INLINE bool LSE_FCALL                               operator <= ( const CFixed<_tType, _uBits> &_tVal ) const {
01892                         return m_tValue <= _tVal.m_tValue;
01893                 }
01894 
01901                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSINT8 _i8Val ) const {
01902                         return m_tValue <= (static_cast<_tType>(_i8Val) << _uBits);
01903                 }
01904 
01911                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSUINT8 _ui8Val ) const {
01912                         return m_tValue <= (static_cast<_tType>(_ui8Val) << _uBits);
01913                 }
01914 
01921                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSINT16 _i16Val ) const {
01922                         return m_tValue <= (static_cast<_tType>(_i16Val) << _uBits);
01923                 }
01924 
01931                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSUINT16 _ui16Val ) const {
01932                         return m_tValue <= (static_cast<_tType>(_ui16Val) << _uBits);
01933                 }
01934 
01941                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSINT32 _i32Val ) const {
01942                         return m_tValue <= (static_cast<_tType>(_i32Val) << _uBits);
01943                 }
01944 
01951                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSUINT32 _ui32Val ) const {
01952                         return m_tValue <= (static_cast<_tType>(_ui32Val) << _uBits);
01953                 }
01954 
01961                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSINT64 _i64Val ) const {
01962                         return m_tValue <= (_i64Val << _uBits);
01963                 }
01964 
01971                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSUINT64 _ui64Val ) const {
01972                         return m_tValue <= (_ui64Val << _uBits);
01973                 }
01974 
01981                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSFLOAT _fVal ) const {
01982                         return m_tValue <= static_cast<_tType>(_fVal * (static_cast<_tType>(1) << _uBits));
01983                 }
01984 
01991                 LSE_INLINE bool LSE_FCALL                               operator <= ( LSDOUBLE _dVal ) const {
01992                         return m_tValue <= static_cast<_tType>(_dVal * (static_cast<_tType>(1) << _uBits));
01993                 }
01994 
02000                 LSE_INLINE LSE_FCALL operator                   LSINT8() const {
02001                         return static_cast<LSINT8>(m_tValue >> _uBits);
02002                 }
02003 
02009                 LSE_INLINE LSE_FCALL operator                   LSINT16() const {
02010                         return static_cast<LSINT16>(m_tValue >> _uBits);
02011                 }
02012 
02018                 LSE_INLINE LSE_FCALL operator                   LSINT32() const {
02019                         return static_cast<LSINT32>(m_tValue >> _uBits);
02020                 }
02021 
02027                 LSE_INLINE LSE_FCALL operator                   LSINT64() const {
02028                         return static_cast<LSINT64>(m_tValue >> _uBits);
02029                 }
02030 
02036                 LSE_INLINE LSE_FCALL operator                   LSFLOAT() const {
02037                         return RecFloat() * m_tValue;
02038                 }
02039 
02045                 LSE_INLINE LSE_FCALL operator                   LSDOUBLE() const {
02046                         return RecDouble() * m_tValue;
02047                 }
02048 
02054                 LSE_INLINE LSE_FCALL operator                   bool() const {
02055                         return m_tValue != 0;
02056                 }
02057 
02063                 LSE_INLINE LSE_FCALL operator                   LSUINT8() const {
02064                         return static_cast<LSUINT8>(m_tValue >> _uBits);
02065                 }
02066 
02072                 LSE_INLINE LSE_FCALL operator                   LSUINT16() const {
02073                         return static_cast<LSUINT16>(m_tValue >> _uBits);
02074                 }
02075 
02081                 LSE_INLINE LSE_FCALL operator                   LSUINT32() const {
02082                         return static_cast<LSUINT32>(m_tValue >> _uBits);
02083                 }
02084 
02090                 LSE_INLINE LSE_FCALL operator                   LSUINT64() const {
02091                         return static_cast<LSUINT64>(m_tValue >> _uBits);
02092                 }
02093 
02099                 LSE_INLINE _tType LSE_FCALL                             GetRawValue() const {
02100                         return m_tValue;
02101                 }
02102 
02103         protected :
02104                 // == Members.
02105                 // Our actual value.
02106                 _tType                                                                  m_tValue;
02107 
02108                 
02109                 // == Functions.
02117                 static LSUINT32 LSE_FCALL                               HighestBit( LSINT64 _i64Value ) {
02118                         if ( _i64Value < 0LL ) {
02119                                 _i64Value = -_i64Value;
02120                         }
02121 #ifdef LSE_X86
02122                         // On x86 processors there is an instruction that gets the highest-
02123                         //      set bit automatically.
02124                         LSUINT32 ui32Ret;
02125                         LSINT32 i32High = static_cast<LSINT32>(_i64Value >> 32ULL);
02126                         LSE_ASM_BEGIN
02127                                 mov eax, 0
02128                                 bsr eax, i32High
02129                                 mov ui32Ret, eax
02130                         LSE_ASM_END
02131                         if ( ui32Ret ) {
02132                                 return ui32Ret + 32UL;
02133                         }
02134 
02135                         i32High = static_cast<LSINT32>(_i64Value & 0xFFFFFFFFULL);
02136                         LSE_ASM_BEGIN
02137                                 mov eax, 0
02138                                 bsr eax, i32High
02139                                 mov ui32Ret, eax
02140                         LSE_ASM_END
02141                         return ui32Ret;
02142 #else   // LSE_X86
02143                         // Get it the hard way.
02144                         LSUINT32 ui32Ret = (sizeof( _i64Value ) << 3UL);
02145                         for ( ; ui32Ret--;  ) {
02146                                 if ( _i64Value & (1LL << ui32Ret) ) { return ui32Ret; }
02147                         }
02148                         return 0;
02149 #endif  // LSE_X86
02150                 }
02151         };
02152 
02153 }       // namespace lsm
02154 
02155 
02156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
02157 // GLOBAL OPERATORS
02158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
02166 template <typename _tType, unsigned _uBits>
02167 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSINT8 _i8Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02168         return _tVal + _i8Val;
02169 }
02170 
02178 template <typename _tType, unsigned _uBits>
02179 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSUINT8 _ui8Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02180         return _tVal + _ui8Val;
02181 }
02182 
02190 template <typename _tType, unsigned _uBits>
02191 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSINT16 _i16Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02192         return _tVal + _i16Val;
02193 }
02194 
02202 template <typename _tType, unsigned _uBits>
02203 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSUINT16 _ui16Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02204         return _tVal + _ui16Val;
02205 }
02206 
02214 template <typename _tType, unsigned _uBits>
02215 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSINT32 _i32Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02216         return _tVal + _i32Val;
02217 }
02218 
02226 template <typename _tType, unsigned _uBits>
02227 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSUINT32 _ui32Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02228         return _tVal + _ui32Val;
02229 }
02230 
02238 template <typename _tType, unsigned _uBits>
02239 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSINT64 _i64Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02240         return _tVal + _i64Val;
02241 }
02242 
02250 template <typename _tType, unsigned _uBits>
02251 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSUINT64 _ui64Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02252         return _tVal + _ui64Val;
02253 }
02254 
02262 template <typename _tType, unsigned _uBits>
02263 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02264         return _tVal + _fVal;
02265 }
02266 
02274 template <typename _tType, unsigned _uBits>
02275 LSE_INLINE lsm::CFixed<_tType, _uBits> operator + ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02276         return _tVal + _dVal;
02277 }
02278 
02286 template <typename _tType, unsigned _uBits>
02287 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSINT8 _i8Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02288         return lsm::CFixed<_tType, _uBits>( _i8Val ) - _tVal;
02289 }
02290 
02298 template <typename _tType, unsigned _uBits>
02299 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSUINT8 _ui8Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02300         return lsm::CFixed<_tType, _uBits>( _ui8Val ) - _tVal;
02301 }
02302 
02310 template <typename _tType, unsigned _uBits>
02311 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSINT16 _i16Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02312         return lsm::CFixed<_tType, _uBits>( _i16Val ) - _tVal;
02313 }
02314 
02322 template <typename _tType, unsigned _uBits>
02323 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSUINT16 _ui16Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02324         return lsm::CFixed<_tType, _uBits>( _ui16Val ) - _tVal;
02325 }
02326 
02334 template <typename _tType, unsigned _uBits>
02335 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSINT32 _i32Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02336         return lsm::CFixed<_tType, _uBits>( _i32Val ) - _tVal;
02337 }
02338 
02346 template <typename _tType, unsigned _uBits>
02347 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSUINT32 _ui32Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02348         return lsm::CFixed<_tType, _uBits>( _ui32Val ) - _tVal;
02349 }
02350 
02358 template <typename _tType, unsigned _uBits>
02359 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSINT64 _i64Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02360         return lsm::CFixed<_tType, _uBits>( _i64Val ) - _tVal;
02361 }
02362 
02370 template <typename _tType, unsigned _uBits>
02371 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSUINT64 _ui64Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02372         return lsm::CFixed<_tType, _uBits>( _ui64Val ) - _tVal;
02373 }
02374 
02382 template <typename _tType, unsigned _uBits>
02383 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02384         return lsm::CFixed<_tType, _uBits>( _fVal ) - _tVal;
02385 }
02386 
02394 template <typename _tType, unsigned _uBits>
02395 LSE_INLINE lsm::CFixed<_tType, _uBits> operator - ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02396         return lsm::CFixed<_tType, _uBits>( _dVal ) - _tVal;
02397 }
02398 
02406 template <typename _tType, unsigned _uBits>
02407 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSINT8 _i8Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02408         return _tVal * _i8Val;
02409 }
02410 
02418 template <typename _tType, unsigned _uBits>
02419 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSUINT8 _ui8Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02420         return _tVal * _ui8Val;
02421 }
02422 
02430 template <typename _tType, unsigned _uBits>
02431 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSINT16 _i16Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02432         return _tVal * _i16Val;
02433 }
02434 
02442 template <typename _tType, unsigned _uBits>
02443 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSUINT16 _ui16Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02444         return _tVal * _ui16Val;
02445 }
02446 
02454 template <typename _tType, unsigned _uBits>
02455 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSINT32 _i32Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02456         return _tVal * _i32Val;
02457 }
02458 
02466 template <typename _tType, unsigned _uBits>
02467 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSUINT32 _ui32Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02468         return _tVal * _ui32Val;
02469 }
02470 
02478 template <typename _tType, unsigned _uBits>
02479 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSINT64 _i64Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02480         return _tVal * _i64Val;
02481 }
02482 
02490 template <typename _tType, unsigned _uBits>
02491 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSUINT64 _ui64Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02492         return _tVal * _ui64Val;
02493 }
02494 
02502 template <typename _tType, unsigned _uBits>
02503 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02504         return _tVal * _fVal;
02505 }
02506 
02514 template <typename _tType, unsigned _uBits>
02515 LSE_INLINE lsm::CFixed<_tType, _uBits> operator * ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02516         return _tVal * _dVal;
02517 }
02518 
02526 template <typename _tType, unsigned _uBits>
02527 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSINT8 _i8Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02528         return lsm::CFixed<_tType, _uBits>( _i8Val ) / _tVal;
02529 }
02530 
02538 template <typename _tType, unsigned _uBits>
02539 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSUINT8 _ui8Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02540         return lsm::CFixed<_tType, _uBits>( _ui8Val ) / _tVal;
02541 }
02542 
02550 template <typename _tType, unsigned _uBits>
02551 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSINT16 _i16Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02552         return lsm::CFixed<_tType, _uBits>( _i16Val ) / _tVal;
02553 }
02554 
02562 template <typename _tType, unsigned _uBits>
02563 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSUINT16 _ui16Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02564         return lsm::CFixed<_tType, _uBits>( _ui16Val ) / _tVal;
02565 }
02566 
02574 template <typename _tType, unsigned _uBits>
02575 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSINT32 _i32Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02576         return lsm::CFixed<_tType, _uBits>( _i32Val ) / _tVal;
02577 }
02578 
02586 template <typename _tType, unsigned _uBits>
02587 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSUINT32 _ui32Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02588         return lsm::CFixed<_tType, _uBits>( _ui32Val ) / _tVal;
02589 }
02590 
02598 template <typename _tType, unsigned _uBits>
02599 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSINT64 _i64Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02600         return lsm::CFixed<_tType, _uBits>( _i64Val ) / _tVal;
02601 }
02602 
02610 template <typename _tType, unsigned _uBits>
02611 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSUINT64 _ui64Val, lsm::CFixed<_tType, _uBits> _tVal ) {
02612         return lsm::CFixed<_tType, _uBits>( _ui64Val ) / _tVal;
02613 }
02614 
02622 template <typename _tType, unsigned _uBits>
02623 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02624         return lsm::CFixed<_tType, _uBits>( _fVal ) / _tVal;
02625 }
02626 
02634 template <typename _tType, unsigned _uBits>
02635 LSE_INLINE lsm::CFixed<_tType, _uBits> operator / ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02636         return lsm::CFixed<_tType, _uBits>( _dVal ) / _tVal;
02637 }
02638 
02646 template <typename _tType, unsigned _uBits>
02647 LSE_INLINE bool operator == ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02648         return _tVal == _fVal;
02649 }
02650 
02658 template <typename _tType, unsigned _uBits>
02659 LSE_INLINE bool operator == ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02660         return _tVal == _dVal;
02661 }
02662 
02670 template <typename _tType, unsigned _uBits>
02671 LSE_INLINE bool operator != ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02672         return _tVal != _fVal;
02673 }
02674 
02682 template <typename _tType, unsigned _uBits>
02683 LSE_INLINE bool operator != ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02684         return _tVal != _dVal;
02685 }
02686 
02694 template <typename _tType, unsigned _uBits>
02695 LSE_INLINE bool operator > ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02696         return lsm::CFixed<_tType, _uBits>( _fVal ) > _tVal;
02697 }
02698 
02706 template <typename _tType, unsigned _uBits>
02707 LSE_INLINE bool operator > ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02708         return lsm::CFixed<_tType, _uBits>( _dVal ) > _tVal;
02709 }
02710 
02718 template <typename _tType, unsigned _uBits>
02719 LSE_INLINE bool operator >= ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02720         return lsm::CFixed<_tType, _uBits>( _fVal ) >= _tVal;
02721 }
02722 
02730 template <typename _tType, unsigned _uBits>
02731 LSE_INLINE bool operator >= ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02732         return lsm::CFixed<_tType, _uBits>( _dVal ) >= _tVal;
02733 }
02734 
02742 template <typename _tType, unsigned _uBits>
02743 LSE_INLINE bool operator < ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02744         return lsm::CFixed<_tType, _uBits>( _fVal ) < _tVal;
02745 }
02746 
02754 template <typename _tType, unsigned _uBits>
02755 LSE_INLINE bool operator < ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02756         return lsm::CFixed<_tType, _uBits>( _dVal ) < _tVal;
02757 }
02758 
02766 template <typename _tType, unsigned _uBits>
02767 LSE_INLINE bool operator <= ( lsstd::LSFLOAT _fVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02768         return lsm::CFixed<_tType, _uBits>( _fVal ) <= _tVal;
02769 }
02770 
02778 template <typename _tType, unsigned _uBits>
02779 LSE_INLINE bool operator <= ( lsstd::LSDOUBLE _dVal, lsm::CFixed<_tType, _uBits> _tVal ) {
02780         return lsm::CFixed<_tType, _uBits>( _dVal ) <= _tVal;
02781 }
02782 
02783 #endif  // __LSM_FIXED_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator