ulp.hpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. /// @addtogroup gtc_ulp
  26. /// @{
  27. /// Return the next ULP value(s) after the input value(s).
  28. ///
  29. /// @tparam genType A floating-point scalar type.
  30. ///
  31. /// @see gtc_ulp
  32. template<typename genType>
  33. GLM_FUNC_DECL genType next_float(genType x);
  34. /// Return the previous ULP value(s) before the input value(s).
  35. ///
  36. /// @tparam genType A floating-point scalar type.
  37. ///
  38. /// @see gtc_ulp
  39. template<typename genType>
  40. GLM_FUNC_DECL genType prev_float(genType x);
  41. /// Return the value(s) ULP distance after the input value(s).
  42. ///
  43. /// @tparam genType A floating-point scalar type.
  44. ///
  45. /// @see gtc_ulp
  46. template<typename genType>
  47. GLM_FUNC_DECL genType next_float(genType x, int ULPs);
  48. /// Return the value(s) ULP distance before the input value(s).
  49. ///
  50. /// @tparam genType A floating-point scalar type.
  51. ///
  52. /// @see gtc_ulp
  53. template<typename genType>
  54. GLM_FUNC_DECL genType prev_float(genType x, int ULPs);
  55. /// Return the distance in the number of ULP between 2 single-precision floating-point scalars.
  56. ///
  57. /// @see gtc_ulp
  58. GLM_FUNC_DECL int float_distance(float x, float y);
  59. /// Return the distance in the number of ULP between 2 double-precision floating-point scalars.
  60. ///
  61. /// @see gtc_ulp
  62. GLM_FUNC_DECL int64 float_distance(double x, double y);
  63. /// Return the next ULP value(s) after the input value(s).
  64. ///
  65. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  66. /// @tparam T Floating-point
  67. /// @tparam Q Value from qualifier enum
  68. ///
  69. /// @see gtc_ulp
  70. template<length_t L, typename T, qualifier Q>
  71. GLM_FUNC_DECL vec<L, T, Q> next_float(vec<L, T, Q> const& x);
  72. /// Return the value(s) ULP distance after the input value(s).
  73. ///
  74. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  75. /// @tparam T Floating-point
  76. /// @tparam Q Value from qualifier enum
  77. ///
  78. /// @see gtc_ulp
  79. template<length_t L, typename T, qualifier Q>
  80. GLM_FUNC_DECL vec<L, T, Q> next_float(vec<L, T, Q> const& x, int ULPs);
  81. /// Return the value(s) ULP distance after the input value(s).
  82. ///
  83. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  84. /// @tparam T Floating-point
  85. /// @tparam Q Value from qualifier enum
  86. ///
  87. /// @see gtc_ulp
  88. template<length_t L, typename T, qualifier Q>
  89. GLM_FUNC_DECL vec<L, T, Q> next_float(vec<L, T, Q> const& x, vec<L, int, Q> const& ULPs);
  90. /// Return the previous ULP value(s) before the input value(s).
  91. ///
  92. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  93. /// @tparam T Floating-point
  94. /// @tparam Q Value from qualifier enum
  95. ///
  96. /// @see gtc_ulp
  97. template<length_t L, typename T, qualifier Q>
  98. GLM_FUNC_DECL vec<L, T, Q> prev_float(vec<L, T, Q> const& x);
  99. /// Return the value(s) ULP distance before the input value(s).
  100. ///
  101. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  102. /// @tparam T Floating-point
  103. /// @tparam Q Value from qualifier enum
  104. ///
  105. /// @see gtc_ulp
  106. template<length_t L, typename T, qualifier Q>
  107. GLM_FUNC_DECL vec<L, T, Q> prev_float(vec<L, T, Q> const& x, int ULPs);
  108. /// Return the value(s) ULP distance before the input value(s).
  109. ///
  110. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  111. /// @tparam T Floating-point
  112. /// @tparam Q Value from qualifier enum
  113. ///
  114. /// @see gtc_ulp
  115. template<length_t L, typename T, qualifier Q>
  116. GLM_FUNC_DECL vec<L, T, Q> prev_float(vec<L, T, Q> const& x, vec<L, int, Q> const& ULPs);
  117. /// Return the distance in the number of ULP between 2 single-precision floating-point scalars.
  118. ///
  119. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  120. /// @tparam Q Value from qualifier enum
  121. ///
  122. /// @see gtc_ulp
  123. template<length_t L, typename T, qualifier Q>
  124. GLM_FUNC_DECL vec<L, int, Q> float_distance(vec<L, float, Q> const& x, vec<L, float, Q> const& y);
  125. /// Return the distance in the number of ULP between 2 double-precision floating-point scalars.
  126. ///
  127. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  128. /// @tparam Q Value from qualifier enum
  129. ///
  130. /// @see gtc_ulp
  131. template<length_t L, typename T, qualifier Q>
  132. GLM_FUNC_DECL vec<L, int64, Q> float_distance(vec<L, double, Q> const& x, vec<L, double, Q> const& y);
  133. /// @}
  134. }//namespace glm
  135. #include "ulp.inl"