Leaked source code of windows server 2003
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.

69 lines
2.2 KiB

  1. /******************************Module*Header*******************************\
  2. *
  3. * *******************
  4. * * GDI SAMPLE CODE *
  5. * *******************
  6. *
  7. * Module Name: math64.h
  8. *
  9. * Additional support for 64 bit math.
  10. *
  11. * Copyright (C) 1995-1999 Microsoft Corporation. All rights reserved.
  12. \**************************************************************************/
  13. #ifndef __MATH64__
  14. #define __MATH64__
  15. //------------------------------------------------------------------------------
  16. //
  17. // We have to be careful of arithmetic overflow in a number of places.
  18. // Fortunately, the compiler is guaranteed to natively support 64-bit
  19. // signed LONGLONGs and 64-bit unsigned DWORDLONGs.
  20. //
  21. // Int32x32To64(a, b) is a macro defined in 'winnt.h' that multiplies
  22. // two 32-bit LONGs to produce a 64-bit LONGLONG result.
  23. //
  24. // UInt64By32To32 is our own macro to divide a 64-bit DWORDLONG by
  25. // a 32-bit ULONG to produce a 32-bit ULONG result.
  26. //
  27. // UInt64Mod32To32 is our own macro to modulus a 64-bit DWORDLONG by
  28. // a 32-bit ULONG to produce a 32-bit ULONG result.
  29. //
  30. //------------------------------------------------------------------------------
  31. #define UInt64Div32To32(a, b) \
  32. ((((DWORDLONG)(a)) > ULONG_MAX) ? \
  33. (ULONG)((DWORDLONG)(a) / (ULONG)(b)) : \
  34. (ULONG)((ULONG)(a) / (ULONG)(b)))
  35. #define UInt64Mod32To32(a, b) \
  36. ((((DWORDLONG)(a)) > ULONG_MAX) ? \
  37. (ULONG)((DWORDLONG)(a) % (ULONG)(b)) : \
  38. (ULONG)((ULONG)(a) % (ULONG)(b)))
  39. //------------------------------------------------------------------------------
  40. // Type conversion functions
  41. //------------------------------------------------------------------------------
  42. static __inline void myFtoi(int *result, float f)
  43. {
  44. #if defined(_X86_)
  45. __asm {
  46. fld f
  47. mov eax,result
  48. fistp dword ptr [eax]
  49. }
  50. #else
  51. *result = (int)f;
  52. #endif
  53. }
  54. static __inline void myFtoui(unsigned long *result, float f)
  55. {
  56. *result = (unsigned long)f;
  57. }
  58. #endif // __MATH64__