1
0

std_math.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef _STD_MATH_H
  2. #define _STD_MATH_H
  3. // FG> doesn't work for me without this include (error C2039: 'sin' : is not a member of '`global namespace'')
  4. #include <math.h>
  5. #include <bfc/platform/types.h>
  6. #ifdef __cplusplus
  7. static inline double SIN(double a) { return ::sin(a); }
  8. static inline double COS(double a) { return ::cos(a); }
  9. static inline double SQRT(double a) { return ::sqrt(a); }
  10. #else
  11. #define SIN(a) sin(a)
  12. #define COS(a) sin(a)
  13. #define SQRT(a) sqrt(a)
  14. unsigned long COMEXP BSWAP_C(unsigned long input);
  15. #endif
  16. #ifdef __cplusplus
  17. // neat trick from C++ book, p. 161
  18. template<class T> inline T MAX(T a, T b) { return a > b ? a : b; }
  19. template<class T> inline T MIN(T a, T b) { return a > b ? b : a; }
  20. template<class T> inline T MINMAX(T a, T minval, T maxval) {
  21. return (a < minval) ? minval : ( (a > maxval) ? maxval : a );
  22. }
  23. // and a couple of my own neat tricks :) BU
  24. template<class T> inline T ABS(T a) { return a < 0 ? -a : a; }
  25. template<class T> inline T SQR(T a) { return a * a; }
  26. template<class T> inline int CMP3(T a, T b) {
  27. if (a < b) return -1;
  28. if (a == b) return 0;
  29. return 1;
  30. }
  31. static inline RGB24 RGBTOBGR(RGB24 col) {
  32. return ((col & 0xFF00FF00) | ((col & 0xFF0000) >> 16) | ((col & 0xFF) << 16));
  33. }
  34. static inline RGB24 BGRTORGB(RGB24 col) { return RGBTOBGR(col); }
  35. static inline ARGB32 BGRATOARGB(ARGB32 col) { return RGBTOBGR(col); }
  36. void premultiplyARGB32(ARGB32 *words, int nwords=1);
  37. #else // not __cplusplus
  38. void COMEXP premultiplyARGB32(ARGB32 *words, int nwords);
  39. #endif
  40. #endif