Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

  1. #ifndef __MATH16_H__
  2. #define __MATH16_H__
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #define SHFTBITS 16
  7. #define LOWMASK ((1 << SHFTBITS)-1)
  8. #define HGHMASK (~LOWMASK)
  9. #define LOWBITS(x) ((x) & LOWMASK)
  10. #define HGHBITS(x) ((x) & HGHMASK)
  11. #define LSHFT(x) ((x) << SHFTBITS)
  12. #define RSHFT(x) ((x) >> SHFTBITS)
  13. #define PI (3373259427 >> (30-SHFTBITS))
  14. #define TWOPI (PI << 1)
  15. #define PIOVER2 (PI >> 1)
  16. #define Need(dw) (dw & 0xFF000000 ? 32 : (dw & 0x00FF0000 ? 24 : (dw & 0x0000FF00 ? 16 : 8)))
  17. int Div16(int iX,int iY);
  18. int Sigmoid16(int iX);
  19. // Greg's multiplication algorithm:
  20. typedef struct {
  21. unsigned short frac;
  22. short whole;
  23. } FIX1616, *PFIX1616;
  24. #define Mul16(a,b,c) { \
  25. int i1, i2; \
  26. FIX1616 fix1, fix2; \
  27. i1=(a); \
  28. i2=(b); \
  29. fix1 = *(PFIX1616)&i1; \
  30. fix2 = *(PFIX1616)&i2; \
  31. c = (unsigned int)(fix1.frac*fix2.frac) >> 16; \
  32. c += fix1.frac*fix2.whole + fix1.whole*fix2.frac; \
  33. c += (fix1.whole*fix2.whole) << 16; \
  34. }
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif // __MATH16_H__