author | sandman <sandman> | 2002-04-16 22:16:56 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-04-16 22:16:56 (UTC) |
commit | ece373988ee95e4dc3c22eeb012a077595740057 (patch) (side-by-side diff) | |
tree | f28fc0976feae59e9b31eae7c17611943cb8a0f2 /noncore/unsupported/qpdf/fixed.h | |
parent | e7e4ecaae60f5444c4ec581077f91e6b412c780c (diff) | |
download | opie-ece373988ee95e4dc3c22eeb012a077595740057.zip opie-ece373988ee95e4dc3c22eeb012a077595740057.tar.gz opie-ece373988ee95e4dc3c22eeb012a077595740057.tar.bz2 |
- fixed a bug with zero-length strings
- introduces macros for fast PDF-debugging
- speedup in math-emulation (rounding,sqrt,fabs)
- libstdc++ not needed anymore
Diffstat (limited to 'noncore/unsupported/qpdf/fixed.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/fixed.h | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/noncore/unsupported/qpdf/fixed.h b/noncore/unsupported/qpdf/fixed.h index 111b95e..c912954 100644 --- a/noncore/unsupported/qpdf/fixed.h +++ b/noncore/unsupported/qpdf/fixed.h @@ -117,12 +117,16 @@ private: friend bool operator < <> ( int i, const fixed &f ); friend bool operator > <> ( int i, const fixed &f ); friend bool operator <= <> ( int i, const fixed &f ); friend bool operator >= <> ( int i, const fixed &f ); friend bool operator == <> ( int i, const fixed &f ); friend bool operator != <> ( int i, const fixed &f ); + + friend long int lrint ( const fixed &f ); + friend fixed sqrt ( const fixed &f ); + friend fixed fabs ( const fixed &f ); #endif }; template <unsigned int SH> inline fixed<SH> operator + ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f( i ) + f. m_f, true ); } template <unsigned int SH> inline fixed<SH> operator - ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f( i ) - f. m_f, true ); } @@ -146,21 +150,37 @@ template <unsigned int SH> inline bool operator < ( int i, const fixed<SH> &f ) template <unsigned int SH> inline bool operator > ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) > f. m_f; } template <unsigned int SH> inline bool operator <= ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) <= f. m_f; } template <unsigned int SH> inline bool operator >= ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) >= f. m_f; } template <unsigned int SH> inline bool operator == ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) == f. m_f; } template <unsigned int SH> inline bool operator != ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) != f. m_f; } - -template <unsigned int SH> inline fixed<SH> sqrt ( const fixed<SH> &f ) +template <unsigned int SH> inline long int lrint ( const fixed<SH> &f ) { - return fixed<SH> ( double( sqrt ( double( f )))); + return fixed<SH>::f2i (( f. m_f < 0 ) ? f. m_f - ( 1 << ( SH - 1 )) : f. m_f + ( 1 << ( SH - 1 ))); } template <unsigned int SH> inline fixed<SH> fabs ( const fixed<SH> &f ) { - return ( f < 0 ) ? -f : f; + return ( f. m_f < 0 ) ? fixed<SH> ( -f. m_f, true ) : f; +} + +// roughly from QPE / qmath.h +template <unsigned int SH> inline fixed<SH> sqrt ( const fixed<SH> &f ) +{ + if ( f. m_f <= 0 ) + return fixed<SH> ( 0, true ); + + fixed<SH>::fix_t a0 = 0; + fixed<SH>::fix_t a1 = f. m_f; // take value as first approximation + + do { + a0 = a1; + a1 = ( a0 + fixed<SH>::div ( f. m_f, a0 )) >> 1; + } while ( abs ( fixed<SH>::div ( a1 - a0, a1 )) > 1 ); + + return fixed<SH> ( a1, true ); } template <unsigned int SH> inline ostream &operator << ( ostream &o, const fixed<SH> &f ) { o << double( f ); return o; |