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.

163 lines
3.9 KiB

  1. /*
  2. * $Id: fltval.h,v 1.7 1995/12/01 18:07:12 dave Exp $
  3. *
  4. * Copyright (c) Microsoft Corp. 1993-1997
  5. * Version 1.1
  6. *
  7. * All rights reserved.
  8. *
  9. * This file contains private, unpublished information and may not be
  10. * copied in part or in whole without express permission of
  11. * Microsoft Corp.
  12. *
  13. */
  14. #ifndef __D3DFLOAT__
  15. #define __D3DFLOAT__
  16. /*
  17. * Convert a value to fixed point at given precision.
  18. */
  19. #define VALTOFXP(d,prec) ((int)SAFE_FLOAT_TO_INT((d) * (double)(1 << (prec))))
  20. extern double RLDDIConvertIEEE[];
  21. __inline int QVALTOFXP(double d, int prec)
  22. {
  23. double tmp = d+RLDDIConvertIEEE[prec];
  24. return *(int *)&tmp;
  25. }
  26. /*
  27. * Convert from fixed point to value.
  28. */
  29. #define FXPTOVAL(f,prec) ((float)(((double)(f)) / (double)(1 << (prec))))
  30. /*
  31. * Convert from integer to fixed point.
  32. */
  33. #define ITOFXP(i,prec) ((i) << (prec))
  34. /*
  35. * Convert from fixed point to integer, truncating.
  36. */
  37. #define FXPTOI(f,prec) ((int)((f) >> (prec)))
  38. /*
  39. * Convert from fixed point to nearest integer greater or equal to f.
  40. */
  41. #define FXPCEIL(f,prec) ((int)(((f) + (1 << (prec)) - 1) >> (prec)))
  42. /*
  43. * Convert a double to fixed point at given precision.
  44. */
  45. #define DTOVALP(d,prec) ((float) (d))
  46. /*
  47. * Convert from fixed point to double.
  48. */
  49. #define VALPTOD(f,prec) ((double) (f))
  50. /*
  51. * Convert from integer to fixed point.
  52. */
  53. #define ITOVALP(i,prec) ((float)(i))
  54. /*
  55. * Convert from fixed point to integer, truncating.
  56. */
  57. #define VALPTOI(f,prec) ((int)(f))
  58. /*
  59. * Convert from fixed point to integer, rounding.
  60. */
  61. #define VALPROUND(f,prec) ((int)((f) + 0.5))
  62. /*
  63. * Convert between fixed point precisions.
  64. */
  65. #define VALPTOVALP(f,from,to) (f)
  66. /*
  67. * Increase the precision of a value.
  68. */
  69. #define INCPREC(f,amount) (f)
  70. /*
  71. * Decrease the precision of a value.
  72. */
  73. #define DECPREC(f,amount) (f)
  74. #define RLDDIFMul8(a, b) ((a) * (b))
  75. #define RLDDIFMul12(a, b) ((a) * (b))
  76. #define RLDDIFMul16(a, b) ((a) * (b))
  77. #define RLDDIFMul24(a, b) ((a) * (b))
  78. #define RLDDIFInvert12(a) (1.0f / (a))
  79. #define RLDDIFInvert16(a) (1.0f / (a))
  80. #define RLDDIFInvert24(a) (1.0f / (a))
  81. #define RLDDIFMulDiv(a, b, c) ((a) * (b) / (c))
  82. #define RLDDIFDiv24(a, b) ((a) / (b))
  83. #define RLDDIFDiv16(a, b) ((a) / (b))
  84. #define RLDDIFDiv12(a, b) ((a) / (b))
  85. #define RLDDIFDiv8(a, b) ((a) / (b))
  86. /*
  87. * RLDDIFDiv8, checking for overflow.
  88. */
  89. #define RLDDICheckDiv8(a, b) ((a) / (b))
  90. /*
  91. * RLDDIFDiv16, checking for overflow.
  92. */
  93. #define RLDDICheckDiv16(a, b) ((a) / (b))
  94. #define RLDDIGetZStep(zl, zr, zm, h3, h1) \
  95. (((zr - zm) * h3 - (zl - zm) * h1) / denom)
  96. #if defined(i386)
  97. #include <limits.h>
  98. #define SAFE_FLOAT_TO_INT(f) ((f) > LONG_MAX \
  99. ? LONG_MAX \
  100. : (f) < LONG_MIN \
  101. ? LONG_MIN \
  102. : (int)(f))
  103. #else
  104. #define SAFE_FLOAT_TO_INT(f) ((int)(f))
  105. #endif
  106. /*
  107. * Normal precision used to store numbers.
  108. */
  109. #define NORMAL_PREC 16
  110. #define DTOVAL(d) DTOVALP(d,NORMAL_PREC)
  111. #define VALTOD(f) VALPTOD(f,NORMAL_PREC)
  112. #define ITOVAL(i) ITOVALP(i,NORMAL_PREC)
  113. #define VALTOI(f) VALPTOI(f,NORMAL_PREC)
  114. #define VALROUND(f) VALPROUND(f,NORMAL_PREC)
  115. #define VALTOFX(f) VALTOFXP(f,NORMAL_PREC)
  116. #define FXTOVAL(f) FXPTOVAL(f,NORMAL_PREC)
  117. #define ITOFX(i) ITOFXP(i,NORMAL_PREC)
  118. #define FXTOI(f) FXPTOI(f,NORMAL_PREC)
  119. #define FXROUND(f) FXPROUND(f,NORMAL_PREC)
  120. #define FXFLOOR(f) FXPTOI(f,NORMAL_PREC)
  121. #define FXCEIL(f) FXPCEIL(f,NORMAL_PREC)
  122. #define VALTOFX24(f) VALTOFXP(f,24)
  123. #define FX24TOVAL(f) FXPTOVAL(f,24)
  124. #define VALTOFX20(f) VALTOFXP(f,20)
  125. #define FX20TOVAL(f) FXPTOVAL(f,20)
  126. #define VALTOFX12(f) VALTOFXP(f,12)
  127. #define FX12TOVAL(f) FXPTOVAL(f,12)
  128. #define VALTOFX8(f) VALTOFXP(f,8)
  129. #define FX8TOVAL(f) FXPTOVAL(f,8)
  130. #endif