ulp.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /// @ref gtc_ulp
  2. /// @file glm/gtc/ulp.hpp
  3. ///
  4. /// @see core (dependence)
  5. ///
  6. /// @defgroup gtc_ulp GLM_GTC_ulp
  7. /// @ingroup gtc
  8. ///
  9. /// Include <glm/gtc/ulp.hpp> to use the features of this extension.
  10. ///
  11. /// Allow the measurement of the accuracy of a function against a reference
  12. /// implementation. This extension works on floating-point data and provide results
  13. /// in ULP.
  14. #pragma once
  15. // Dependencies
  16. #include "../detail/setup.hpp"
  17. #include "../detail/qualifier.hpp"
  18. #include "../detail/_vectorize.hpp"
  19. #include "../ext/scalar_int_sized.hpp"
  20. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  21. # pragma message("GLM: GLM_GTC_ulp extension included")
  22. #endif
  23. namespace glm
  24. {
  25. /// Return the next ULP value(s) after the input value(s).
  26. ///
  27. /// @tparam genType A floating-point scalar type.
  28. ///
  29. /// @see gtc_ulp
  30. template<typename genType>
  31. GLM_FUNC_DECL genType next_float(genType x);
  32. /// Return the previous ULP value(s) before the input value(s).
  33. ///
  34. /// @tparam genType A floating-point scalar type.
  35. ///
  36. /// @see gtc_ulp
  37. template<typename genType>
  38. GLM_FUNC_DECL genType prev_float(genType x);
  39. /// Return the value(s) ULP distance after the input value(s).
  40. ///
  41. /// @tparam genType A floating-point scalar type.
  42. ///
  43. /// @see gtc_ulp
  44. template<typename genType>
  45. GLM_FUNC_DECL genType next_float(genType x, int ULPs);
  46. /// Return the value(s) ULP distance before the input value(s).
  47. ///
  48. /// @tparam genType A floating-point scalar type.
  49. ///
  50. /// @see gtc_ulp
  51. template<typename genType>
  52. GLM_FUNC_DECL genType prev_float(genType x, int ULPs);
  53. /// Return the distance in the number of ULP between 2 single-precision floating-point scalars.
  54. ///
  55. /// @see gtc_ulp
  56. GLM_FUNC_DECL int float_distance(float x, float y);
  57. /// Return the distance in the number of ULP between 2 double-precision floating-point scalars.
  58. ///
  59. /// @see gtc_ulp
  60. GLM_FUNC_DECL int64 float_distance(double x, double y);
  61. /// Return the next ULP value(s) after the input value(s).
  62. ///
  63. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  64. /// @tparam T Floating-point
  65. /// @tparam Q Value from qualifier enum
  66. ///
  67. /// @see gtc_ulp
  68. template<length_t L, typename T, qualifier Q>
  69. GLM_FUNC_DECL vec<L, T, Q> next_float(vec<L, T, Q> const& x);
  70. /// Return the value(s) ULP distance after the input value(s).
  71. ///
  72. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  73. /// @tparam T Floating-point
  74. /// @tparam Q Value from qualifier enum
  75. ///
  76. /// @see gtc_ulp
  77. template<length_t L, typename T, qualifier Q>
  78. GLM_FUNC_DECL vec<L, T, Q> next_float(vec<L, T, Q> const& x, int ULPs);
  79. /// Return the value(s) ULP distance after the input value(s).
  80. ///
  81. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  82. /// @tparam T Floating-point
  83. /// @tparam Q Value from qualifier enum
  84. ///
  85. /// @see gtc_ulp
  86. template<length_t L, typename T, qualifier Q>
  87. GLM_FUNC_DECL vec<L, T, Q> next_float(vec<L, T, Q> const& x, vec<L, int, Q> const& ULPs);
  88. /// Return the previous ULP value(s) before the input value(s).
  89. ///
  90. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  91. /// @tparam T Floating-point
  92. /// @tparam Q Value from qualifier enum
  93. ///
  94. /// @see gtc_ulp
  95. template<length_t L, typename T, qualifier Q>
  96. GLM_FUNC_DECL vec<L, T, Q> prev_float(vec<L, T, Q> const& x);
  97. /// Return the value(s) ULP distance before the input value(s).
  98. ///
  99. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  100. /// @tparam T Floating-point
  101. /// @tparam Q Value from qualifier enum
  102. ///
  103. /// @see gtc_ulp
  104. template<length_t L, typename T, qualifier Q>
  105. GLM_FUNC_DECL vec<L, T, Q> prev_float(vec<L, T, Q> const& x, int ULPs);
  106. /// Return the value(s) ULP distance before the input value(s).
  107. ///
  108. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  109. /// @tparam T Floating-point
  110. /// @tparam Q Value from qualifier enum
  111. ///
  112. /// @see gtc_ulp
  113. template<length_t L, typename T, qualifier Q>
  114. GLM_FUNC_DECL vec<L, T, Q> prev_float(vec<L, T, Q> const& x, vec<L, int, Q> const& ULPs);
  115. /// Return the distance in the number of ULP between 2 single-precision floating-point scalars.
  116. ///
  117. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  118. /// @tparam Q Value from qualifier enum
  119. ///
  120. /// @see gtc_ulp
  121. template<length_t L, typename T, qualifier Q>
  122. GLM_FUNC_DECL vec<L, int, Q> float_distance(vec<L, float, Q> const& x, vec<L, float, Q> const& y);
  123. /// Return the distance in the number of ULP between 2 double-precision floating-point scalars.
  124. ///
  125. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  126. /// @tparam Q Value from qualifier enum
  127. ///
  128. /// @see gtc_ulp
  129. template<length_t L, typename T, qualifier Q>
  130. GLM_FUNC_DECL vec<L, int64, Q> float_distance(vec<L, double, Q> const& x, vec<L, double, Q> const& y);
  131. /// @}
  132. }//namespace glm
  133. #include "ulp.inl"