TMath.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * Helpers for fixedpoint math
  3. * Copyright (c) 2010 Nokia Corporation.
  4. */
  5. #ifndef __TMATH__
  6. #define __TMATH__
  7. #include "TBase.h"
  8. #define FP_BITS 14
  9. #define FP_HALFBITS 7
  10. #define FP_AND 16383
  11. #define FP_VAL 16384
  12. inline TSDWORD tmath_fixedCeil(const TSDWORD x) { return ((x+FP_AND) >> FP_BITS); }
  13. #ifndef WIN32
  14. #ifndef __int64
  15. #define __int64 long long int
  16. #endif
  17. #endif
  18. //TSDWORD tmath_sqrt( TSDWORD i );
  19. TSDWORD tmath_sqrt(__int64 r);
  20. TSDWORD tmath_fpsqrt( const TSDWORD i );
  21. TSDWORD tmath_fpmul( const TSDWORD i1, const TSDWORD i2);
  22. TSDWORD tmath_fpdiv( const TSDWORD i1, const TSDWORD i2 );
  23. TSDWORD tmath_fpmuldiv( const TSDWORD m1, const TSDWORD m2, const TSDWORD div );
  24. inline TSDWORD tmath_abs( const TSDWORD m1 ) { if (m1<0) return -m1; else return m1; }
  25. TSDWORD tmath_interpolate( const TSDWORD m1, const TSDWORD m2, const TSDWORD shr );
  26. TSDWORD tmath_angle( TSDWORD vx, TSDWORD vy );
  27. float tmath_realsqrt( float val );
  28. float tmath_sin( float angle );
  29. float tmath_cos( float angle );
  30. #define TMATH_TABLE_LENGTH 1024
  31. #define TMATH_TABLE_AND 1023
  32. class CTMath {
  33. public:
  34. CTMath();
  35. ~CTMath();
  36. TSDWORD cos( TSDWORD amount );
  37. TSDWORD sin( TSDWORD amount );
  38. TSDWORD cos_table[TMATH_TABLE_LENGTH];
  39. };
  40. #endif