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.

154 lines
3.4 KiB

  1. /*
  2. * $Id: fltval.h,v 1.7 1995/12/01 18:07:12 dave Exp $
  3. *
  4. * Copyright (c) RenderMorphics Ltd. 1993, 1994
  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. * RenderMorphics Ltd.
  12. *
  13. */
  14. #ifndef __RLFLOAT__
  15. #define __RLFLOAT__
  16. /*
  17. * Floating point versions of fixed point math.
  18. */
  19. typedef float RLDDIValue;
  20. typedef int RLDDIFixed;
  21. #define VAL_MAX ((RLDDIValue) 1e30)
  22. #define VAL_MIN ((RLDDIValue) (-1e30))
  23. /*
  24. * Convert a value to fixed point at given precision.
  25. */
  26. #define VALTOFXP(d,prec) ((RLDDIFixed)SAFE_FLOAT_TO_INT((d) * (double)(1 << (prec))))
  27. extern double RLDDIConvertIEEE[];
  28. // The macro form can cause problems when used multiple times in
  29. // a function invocation due to its use of a global
  30. // Fortunately, inline functions work in our compiler
  31. __inline RLDDIFixed QVALTOFXP(double d, int prec)
  32. {
  33. double tmp = d+RLDDIConvertIEEE[prec];
  34. return *(RLDDIFixed *)&tmp;
  35. }
  36. /*
  37. * Convert from fixed point to value.
  38. */
  39. #define FXPTOVAL(f,prec) ((RLDDIValue)(((double)(f)) / (double)(1 << (prec))))
  40. /*
  41. * Convert from integer to fixed point.
  42. */
  43. #define ITOFXP(i,prec) ((i) << (prec))
  44. /*
  45. * Convert from fixed point to integer, truncating.
  46. */
  47. #define FXPTOI(f,prec) ((int)((f) >> (prec)))
  48. /*
  49. * Convert from fixed point to integer, rounding.
  50. */
  51. #define FXPROUND(f,prec) ((int)(((f) + (1 << ((prec) - 1))) >> (prec)))
  52. /*
  53. * Convert from fixed point to nearest integer greater or equal to f.
  54. */
  55. #define FXPCEIL(f,prec) ((int)(((f) + (1 << (prec)) - 1) >> (prec)))
  56. /*
  57. * Convert a double to fixed point at given precision.
  58. */
  59. #define DTOVALP(d,prec) ((RLDDIValue) (d))
  60. /*
  61. * Convert from fixed point to double.
  62. */
  63. #define VALPTOD(f,prec) ((double) (f))
  64. /*
  65. * Convert from integer to fixed point.
  66. */
  67. #define ITOVALP(i,prec) ((RLDDIValue)(i))
  68. /*
  69. * Convert from fixed point to integer, truncating.
  70. */
  71. #define VALPTOI(f,prec) ((int)(f))
  72. /*
  73. * Convert from fixed point to integer, rounding.
  74. */
  75. #define VALPROUND(f,prec) ((int)((f) + 0.5))
  76. /*
  77. * Convert between fixed point precisions.
  78. */
  79. #define VALPTOVALP(f,from,to) (f)
  80. /*
  81. * Increase the precision of a value.
  82. */
  83. #define INCPREC(f,amount) (f)
  84. /*
  85. * Decrease the precision of a value.
  86. */
  87. #define DECPREC(f,amount) (f)
  88. #define RLDDIFMul8(a, b) ((a) * (b))
  89. #define RLDDIFMul12(a, b) ((a) * (b))
  90. #define RLDDIFMul16(a, b) ((a) * (b))
  91. #define RLDDIFMul24(a, b) ((a) * (b))
  92. #define RLDDIFInvert12(a) (1.0f / (a))
  93. #define RLDDIFInvert16(a) (1.0f / (a))
  94. #define RLDDIFInvert24(a) (1.0f / (a))
  95. #define RLDDIFMulDiv(a, b, c) ((a) * (b) / (c))
  96. #define RLDDIFDiv24(a, b) ((a) / (b))
  97. #define RLDDIFDiv16(a, b) ((a) / (b))
  98. #define RLDDIFDiv12(a, b) ((a) / (b))
  99. #define RLDDIFDiv8(a, b) ((a) / (b))
  100. /*
  101. * RLDDIFDiv8, checking for overflow.
  102. */
  103. #define RLDDICheckDiv8(a, b) ((a) / (b))
  104. /*
  105. * RLDDIFDiv16, checking for overflow.
  106. */
  107. #define RLDDICheckDiv16(a, b) ((a) / (b))
  108. #define RLDDIGetZStep(zl, zr, zm, h3, h1) \
  109. (((zr - zm) * h3 - (zl - zm) * h1) / denom)
  110. #if defined(i386)
  111. #include <limits.h>
  112. #define SAFE_FLOAT_TO_INT(f) ((f) > LONG_MAX \
  113. ? LONG_MAX \
  114. : (f) < LONG_MIN \
  115. ? LONG_MIN \
  116. : (RLDDIFixed)(f))
  117. #else
  118. #define SAFE_FLOAT_TO_INT(f) ((RLDDIFixed)(f))
  119. #endif
  120. #endif