common.hpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. /// @ref core
  2. /// @file glm/common.hpp
  3. ///
  4. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  5. ///
  6. /// @defgroup core_func_common Common functions
  7. /// @ingroup core
  8. ///
  9. /// Provides GLSL common functions
  10. ///
  11. /// These all operate component-wise. The description is per component.
  12. ///
  13. /// Include <glm/common.hpp> to use these core features.
  14. #pragma once
  15. #include "detail/qualifier.hpp"
  16. #include "detail/_fixes.hpp"
  17. namespace glm
  18. {
  19. /// @addtogroup core_func_common
  20. /// @{
  21. /// Returns x if x >= 0; otherwise, it returns -x.
  22. ///
  23. /// @tparam genType floating-point or signed integer; scalar or vector types.
  24. ///
  25. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/abs.xml">GLSL abs man page</a>
  26. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  27. template<typename genType>
  28. GLM_FUNC_DECL GLM_CONSTEXPR genType abs(genType x);
  29. /// Returns x if x >= 0; otherwise, it returns -x.
  30. ///
  31. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  32. /// @tparam T Floating-point or signed integer scalar types
  33. /// @tparam Q Value from qualifier enum
  34. ///
  35. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/abs.xml">GLSL abs man page</a>
  36. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  37. template<length_t L, typename T, qualifier Q>
  38. GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> abs(vec<L, T, Q> const& x);
  39. /// Returns 1.0 if x > 0, 0.0 if x == 0, or -1.0 if x < 0.
  40. ///
  41. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  42. /// @tparam T Floating-point scalar types
  43. /// @tparam Q Value from qualifier enum
  44. ///
  45. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/sign.xml">GLSL sign man page</a>
  46. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  47. template<length_t L, typename T, qualifier Q>
  48. GLM_FUNC_DECL vec<L, T, Q> sign(vec<L, T, Q> const& x);
  49. /// Returns a value equal to the nearest integer that is less then or equal to x.
  50. ///
  51. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  52. /// @tparam T Floating-point scalar types
  53. /// @tparam Q Value from qualifier enum
  54. ///
  55. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floor.xml">GLSL floor man page</a>
  56. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  57. template<length_t L, typename T, qualifier Q>
  58. GLM_FUNC_DECL vec<L, T, Q> floor(vec<L, T, Q> const& x);
  59. /// Returns a value equal to the nearest integer to x
  60. /// whose absolute value is not larger than the absolute value of x.
  61. ///
  62. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  63. /// @tparam T Floating-point scalar types
  64. /// @tparam Q Value from qualifier enum
  65. ///
  66. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/trunc.xml">GLSL trunc man page</a>
  67. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  68. template<length_t L, typename T, qualifier Q>
  69. GLM_FUNC_DECL vec<L, T, Q> trunc(vec<L, T, Q> const& x);
  70. /// Returns a value equal to the nearest integer to x.
  71. /// The fraction 0.5 will round in a direction chosen by the
  72. /// implementation, presumably the direction that is fastest.
  73. /// This includes the possibility that round(x) returns the
  74. /// same value as roundEven(x) for all values of x.
  75. ///
  76. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  77. /// @tparam T Floating-point scalar types
  78. /// @tparam Q Value from qualifier enum
  79. ///
  80. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/round.xml">GLSL round man page</a>
  81. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  82. template<length_t L, typename T, qualifier Q>
  83. GLM_FUNC_DECL vec<L, T, Q> round(vec<L, T, Q> const& x);
  84. /// Returns a value equal to the nearest integer to x.
  85. /// A fractional part of 0.5 will round toward the nearest even
  86. /// integer. (Both 3.5 and 4.5 for x will return 4.0.)
  87. ///
  88. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  89. /// @tparam T Floating-point scalar types
  90. /// @tparam Q Value from qualifier enum
  91. ///
  92. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/roundEven.xml">GLSL roundEven man page</a>
  93. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  94. /// @see <a href="http://developer.amd.com/documentation/articles/pages/New-Round-to-Even-Technique.aspx">New round to even technique</a>
  95. template<length_t L, typename T, qualifier Q>
  96. GLM_FUNC_DECL vec<L, T, Q> roundEven(vec<L, T, Q> const& x);
  97. /// Returns a value equal to the nearest integer
  98. /// that is greater than or equal to x.
  99. ///
  100. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  101. /// @tparam T Floating-point scalar types
  102. /// @tparam Q Value from qualifier enum
  103. ///
  104. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/ceil.xml">GLSL ceil man page</a>
  105. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  106. template<length_t L, typename T, qualifier Q>
  107. GLM_FUNC_DECL vec<L, T, Q> ceil(vec<L, T, Q> const& x);
  108. /// Return x - floor(x).
  109. ///
  110. /// @tparam genType Floating-point scalar or vector types.
  111. ///
  112. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/fract.xml">GLSL fract man page</a>
  113. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  114. template<typename genType>
  115. GLM_FUNC_DECL genType fract(genType x);
  116. /// Return x - floor(x).
  117. ///
  118. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  119. /// @tparam T Floating-point scalar types
  120. /// @tparam Q Value from qualifier enum
  121. ///
  122. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/fract.xml">GLSL fract man page</a>
  123. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  124. template<length_t L, typename T, qualifier Q>
  125. GLM_FUNC_DECL vec<L, T, Q> fract(vec<L, T, Q> const& x);
  126. template<typename genType>
  127. GLM_FUNC_DECL genType mod(genType x, genType y);
  128. template<length_t L, typename T, qualifier Q>
  129. GLM_FUNC_DECL vec<L, T, Q> mod(vec<L, T, Q> const& x, T y);
  130. /// Modulus. Returns x - y * floor(x / y)
  131. /// for each component in x using the floating point value y.
  132. ///
  133. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  134. /// @tparam T Floating-point scalar types, include glm/gtc/integer for integer scalar types support
  135. /// @tparam Q Value from qualifier enum
  136. ///
  137. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/mod.xml">GLSL mod man page</a>
  138. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  139. template<length_t L, typename T, qualifier Q>
  140. GLM_FUNC_DECL vec<L, T, Q> mod(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
  141. /// Returns the fractional part of x and sets i to the integer
  142. /// part (as a whole number floating point value). Both the
  143. /// return value and the output parameter will have the same
  144. /// sign as x.
  145. ///
  146. /// @tparam genType Floating-point scalar or vector types.
  147. ///
  148. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/modf.xml">GLSL modf man page</a>
  149. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  150. template<typename genType>
  151. GLM_FUNC_DECL genType modf(genType x, genType& i);
  152. /// Returns y if y < x; otherwise, it returns x.
  153. ///
  154. /// @tparam genType Floating-point or integer; scalar or vector types.
  155. ///
  156. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/min.xml">GLSL min man page</a>
  157. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  158. template<typename genType>
  159. GLM_FUNC_DECL GLM_CONSTEXPR genType min(genType x, genType y);
  160. /// Returns y if y < x; otherwise, it returns x.
  161. ///
  162. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  163. /// @tparam T Floating-point or integer scalar types
  164. /// @tparam Q Value from qualifier enum
  165. ///
  166. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/min.xml">GLSL min man page</a>
  167. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  168. template<length_t L, typename T, qualifier Q>
  169. GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> min(vec<L, T, Q> const& x, T y);
  170. /// Returns y if y < x; otherwise, it returns x.
  171. ///
  172. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  173. /// @tparam T Floating-point or integer scalar types
  174. /// @tparam Q Value from qualifier enum
  175. ///
  176. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/min.xml">GLSL min man page</a>
  177. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  178. template<length_t L, typename T, qualifier Q>
  179. GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> min(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
  180. /// Returns y if x < y; otherwise, it returns x.
  181. ///
  182. /// @tparam genType Floating-point or integer; scalar or vector types.
  183. ///
  184. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/max.xml">GLSL max man page</a>
  185. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  186. template<typename genType>
  187. GLM_FUNC_DECL GLM_CONSTEXPR genType max(genType x, genType y);
  188. /// Returns y if x < y; otherwise, it returns x.
  189. ///
  190. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  191. /// @tparam T Floating-point or integer scalar types
  192. /// @tparam Q Value from qualifier enum
  193. ///
  194. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/max.xml">GLSL max man page</a>
  195. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  196. template<length_t L, typename T, qualifier Q>
  197. GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> max(vec<L, T, Q> const& x, T y);
  198. /// Returns y if x < y; otherwise, it returns x.
  199. ///
  200. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  201. /// @tparam T Floating-point or integer scalar types
  202. /// @tparam Q Value from qualifier enum
  203. ///
  204. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/max.xml">GLSL max man page</a>
  205. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  206. template<length_t L, typename T, qualifier Q>
  207. GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> max(vec<L, T, Q> const& x, vec<L, T, Q> const& y);
  208. /// Returns min(max(x, minVal), maxVal) for each component in x
  209. /// using the floating-point values minVal and maxVal.
  210. ///
  211. /// @tparam genType Floating-point or integer; scalar or vector types.
  212. ///
  213. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/clamp.xml">GLSL clamp man page</a>
  214. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  215. template<typename genType>
  216. GLM_FUNC_DECL GLM_CONSTEXPR genType clamp(genType x, genType minVal, genType maxVal);
  217. /// Returns min(max(x, minVal), maxVal) for each component in x
  218. /// using the floating-point values minVal and maxVal.
  219. ///
  220. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  221. /// @tparam T Floating-point or integer scalar types
  222. /// @tparam Q Value from qualifier enum
  223. ///
  224. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/clamp.xml">GLSL clamp man page</a>
  225. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  226. template<length_t L, typename T, qualifier Q>
  227. GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> clamp(vec<L, T, Q> const& x, T minVal, T maxVal);
  228. /// Returns min(max(x, minVal), maxVal) for each component in x
  229. /// using the floating-point values minVal and maxVal.
  230. ///
  231. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  232. /// @tparam T Floating-point or integer scalar types
  233. /// @tparam Q Value from qualifier enum
  234. ///
  235. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/clamp.xml">GLSL clamp man page</a>
  236. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  237. template<length_t L, typename T, qualifier Q>
  238. GLM_FUNC_DECL GLM_CONSTEXPR vec<L, T, Q> clamp(vec<L, T, Q> const& x, vec<L, T, Q> const& minVal, vec<L, T, Q> const& maxVal);
  239. /// If genTypeU is a floating scalar or vector:
  240. /// Returns x * (1.0 - a) + y * a, i.e., the linear blend of
  241. /// x and y using the floating-point value a.
  242. /// The value for a is not restricted to the range [0, 1].
  243. ///
  244. /// If genTypeU is a boolean scalar or vector:
  245. /// Selects which vector each returned component comes
  246. /// from. For a component of 'a' that is false, the
  247. /// corresponding component of 'x' is returned. For a
  248. /// component of 'a' that is true, the corresponding
  249. /// component of 'y' is returned. Components of 'x' and 'y' that
  250. /// are not selected are allowed to be invalid floating point
  251. /// values and will have no effect on the results. Thus, this
  252. /// provides different functionality than
  253. /// genType mix(genType x, genType y, genType(a))
  254. /// where a is a Boolean vector.
  255. ///
  256. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/mix.xml">GLSL mix man page</a>
  257. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  258. ///
  259. /// @param[in] x Value to interpolate.
  260. /// @param[in] y Value to interpolate.
  261. /// @param[in] a Interpolant.
  262. ///
  263. /// @tparam genTypeT Floating point scalar or vector.
  264. /// @tparam genTypeU Floating point or boolean scalar or vector. It can't be a vector if it is the length of genTypeT.
  265. ///
  266. /// @code
  267. /// #include <glm/glm.hpp>
  268. /// ...
  269. /// float a;
  270. /// bool b;
  271. /// glm::dvec3 e;
  272. /// glm::dvec3 f;
  273. /// glm::vec4 g;
  274. /// glm::vec4 h;
  275. /// ...
  276. /// glm::vec4 r = glm::mix(g, h, a); // Interpolate with a floating-point scalar two vectors.
  277. /// glm::vec4 s = glm::mix(g, h, b); // Returns g or h;
  278. /// glm::dvec3 t = glm::mix(e, f, a); // Types of the third parameter is not required to match with the first and the second.
  279. /// glm::vec4 u = glm::mix(g, h, r); // Interpolations can be perform per component with a vector for the last parameter.
  280. /// @endcode
  281. template<typename genTypeT, typename genTypeU>
  282. GLM_FUNC_DECL genTypeT mix(genTypeT x, genTypeT y, genTypeU a);
  283. template<length_t L, typename T, typename U, qualifier Q>
  284. GLM_FUNC_DECL vec<L, T, Q> mix(vec<L, T, Q> const& x, vec<L, T, Q> const& y, vec<L, U, Q> const& a);
  285. template<length_t L, typename T, typename U, qualifier Q>
  286. GLM_FUNC_DECL vec<L, T, Q> mix(vec<L, T, Q> const& x, vec<L, T, Q> const& y, U a);
  287. /// Returns 0.0 if x < edge, otherwise it returns 1.0 for each component of a genType.
  288. ///
  289. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a>
  290. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  291. template<typename genType>
  292. GLM_FUNC_DECL genType step(genType edge, genType x);
  293. /// Returns 0.0 if x < edge, otherwise it returns 1.0.
  294. ///
  295. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  296. /// @tparam T Floating-point scalar types
  297. /// @tparam Q Value from qualifier enum
  298. ///
  299. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a>
  300. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  301. template<length_t L, typename T, qualifier Q>
  302. GLM_FUNC_DECL vec<L, T, Q> step(T edge, vec<L, T, Q> const& x);
  303. /// Returns 0.0 if x < edge, otherwise it returns 1.0.
  304. ///
  305. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  306. /// @tparam T Floating-point scalar types
  307. /// @tparam Q Value from qualifier enum
  308. ///
  309. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/step.xml">GLSL step man page</a>
  310. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  311. template<length_t L, typename T, qualifier Q>
  312. GLM_FUNC_DECL vec<L, T, Q> step(vec<L, T, Q> const& edge, vec<L, T, Q> const& x);
  313. /// Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and
  314. /// performs smooth Hermite interpolation between 0 and 1
  315. /// when edge0 < x < edge1. This is useful in cases where
  316. /// you would want a threshold function with a smooth
  317. /// transition. This is equivalent to:
  318. /// genType t;
  319. /// t = clamp ((x - edge0) / (edge1 - edge0), 0, 1);
  320. /// return t * t * (3 - 2 * t);
  321. /// Results are undefined if edge0 >= edge1.
  322. ///
  323. /// @tparam genType Floating-point scalar or vector types.
  324. ///
  325. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/smoothstep.xml">GLSL smoothstep man page</a>
  326. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  327. template<typename genType>
  328. GLM_FUNC_DECL genType smoothstep(genType edge0, genType edge1, genType x);
  329. template<length_t L, typename T, qualifier Q>
  330. GLM_FUNC_DECL vec<L, T, Q> smoothstep(T edge0, T edge1, vec<L, T, Q> const& x);
  331. template<length_t L, typename T, qualifier Q>
  332. GLM_FUNC_DECL vec<L, T, Q> smoothstep(vec<L, T, Q> const& edge0, vec<L, T, Q> const& edge1, vec<L, T, Q> const& x);
  333. /// Returns true if x holds a NaN (not a number)
  334. /// representation in the underlying implementation's set of
  335. /// floating point representations. Returns false otherwise,
  336. /// including for implementations with no NaN
  337. /// representations.
  338. ///
  339. /// /!\ When using compiler fast math, this function may fail.
  340. ///
  341. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  342. /// @tparam T Floating-point scalar types
  343. /// @tparam Q Value from qualifier enum
  344. ///
  345. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/isnan.xml">GLSL isnan man page</a>
  346. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  347. template<length_t L, typename T, qualifier Q>
  348. GLM_FUNC_DECL vec<L, bool, Q> isnan(vec<L, T, Q> const& x);
  349. /// Returns true if x holds a positive infinity or negative
  350. /// infinity representation in the underlying implementation's
  351. /// set of floating point representations. Returns false
  352. /// otherwise, including for implementations with no infinity
  353. /// representations.
  354. ///
  355. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  356. /// @tparam T Floating-point scalar types
  357. /// @tparam Q Value from qualifier enum
  358. ///
  359. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/isinf.xml">GLSL isinf man page</a>
  360. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  361. template<length_t L, typename T, qualifier Q>
  362. GLM_FUNC_DECL vec<L, bool, Q> isinf(vec<L, T, Q> const& x);
  363. /// Returns a signed integer value representing
  364. /// the encoding of a floating-point value. The floating-point
  365. /// value's bit-level representation is preserved.
  366. ///
  367. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToInt.xml">GLSL floatBitsToInt man page</a>
  368. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  369. GLM_FUNC_DECL int floatBitsToInt(float const& v);
  370. /// Returns a signed integer value representing
  371. /// the encoding of a floating-point value. The floatingpoint
  372. /// value's bit-level representation is preserved.
  373. ///
  374. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  375. /// @tparam Q Value from qualifier enum
  376. ///
  377. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToInt.xml">GLSL floatBitsToInt man page</a>
  378. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  379. template<length_t L, qualifier Q>
  380. GLM_FUNC_DECL vec<L, int, Q> floatBitsToInt(vec<L, float, Q> const& v);
  381. /// Returns a unsigned integer value representing
  382. /// the encoding of a floating-point value. The floatingpoint
  383. /// value's bit-level representation is preserved.
  384. ///
  385. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToUint.xml">GLSL floatBitsToUint man page</a>
  386. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  387. GLM_FUNC_DECL uint floatBitsToUint(float const& v);
  388. /// Returns a unsigned integer value representing
  389. /// the encoding of a floating-point value. The floatingpoint
  390. /// value's bit-level representation is preserved.
  391. ///
  392. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  393. /// @tparam Q Value from qualifier enum
  394. ///
  395. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/floatBitsToUint.xml">GLSL floatBitsToUint man page</a>
  396. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  397. template<length_t L, qualifier Q>
  398. GLM_FUNC_DECL vec<L, uint, Q> floatBitsToUint(vec<L, float, Q> const& v);
  399. /// Returns a floating-point value corresponding to a signed
  400. /// integer encoding of a floating-point value.
  401. /// If an inf or NaN is passed in, it will not signal, and the
  402. /// resulting floating point value is unspecified. Otherwise,
  403. /// the bit-level representation is preserved.
  404. ///
  405. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/intBitsToFloat.xml">GLSL intBitsToFloat man page</a>
  406. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  407. GLM_FUNC_DECL float intBitsToFloat(int const& v);
  408. /// Returns a floating-point value corresponding to a signed
  409. /// integer encoding of a floating-point value.
  410. /// If an inf or NaN is passed in, it will not signal, and the
  411. /// resulting floating point value is unspecified. Otherwise,
  412. /// the bit-level representation is preserved.
  413. ///
  414. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  415. /// @tparam Q Value from qualifier enum
  416. ///
  417. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/intBitsToFloat.xml">GLSL intBitsToFloat man page</a>
  418. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  419. template<length_t L, qualifier Q>
  420. GLM_FUNC_DECL vec<L, float, Q> intBitsToFloat(vec<L, int, Q> const& v);
  421. /// Returns a floating-point value corresponding to a
  422. /// unsigned integer encoding of a floating-point value.
  423. /// If an inf or NaN is passed in, it will not signal, and the
  424. /// resulting floating point value is unspecified. Otherwise,
  425. /// the bit-level representation is preserved.
  426. ///
  427. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uintBitsToFloat.xml">GLSL uintBitsToFloat man page</a>
  428. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  429. GLM_FUNC_DECL float uintBitsToFloat(uint const& v);
  430. /// Returns a floating-point value corresponding to a
  431. /// unsigned integer encoding of a floating-point value.
  432. /// If an inf or NaN is passed in, it will not signal, and the
  433. /// resulting floating point value is unspecified. Otherwise,
  434. /// the bit-level representation is preserved.
  435. ///
  436. /// @tparam L Integer between 1 and 4 included that qualify the dimension of the vector
  437. /// @tparam Q Value from qualifier enum
  438. ///
  439. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/uintBitsToFloat.xml">GLSL uintBitsToFloat man page</a>
  440. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  441. template<length_t L, qualifier Q>
  442. GLM_FUNC_DECL vec<L, float, Q> uintBitsToFloat(vec<L, uint, Q> const& v);
  443. /// Computes and returns a * b + c.
  444. ///
  445. /// @tparam genType Floating-point scalar or vector types.
  446. ///
  447. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/fma.xml">GLSL fma man page</a>
  448. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  449. template<typename genType>
  450. GLM_FUNC_DECL genType fma(genType const& a, genType const& b, genType const& c);
  451. /// Splits x into a floating-point significand in the range
  452. /// [0.5, 1.0) and an integral exponent of two, such that:
  453. /// x = significand * exp(2, exponent)
  454. ///
  455. /// The significand is returned by the function and the
  456. /// exponent is returned in the parameter exp. For a
  457. /// floating-point value of zero, the significant and exponent
  458. /// are both zero. For a floating-point value that is an
  459. /// infinity or is not a number, the results are undefined.
  460. ///
  461. /// @tparam genType Floating-point scalar or vector types.
  462. ///
  463. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/frexp.xml">GLSL frexp man page</a>
  464. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  465. template<typename genType>
  466. GLM_FUNC_DECL genType frexp(genType x, int& exp);
  467. template<length_t L, typename T, qualifier Q>
  468. GLM_FUNC_DECL vec<L, T, Q> frexp(vec<L, T, Q> const& v, vec<L, int, Q>& exp);
  469. /// Builds a floating-point number from x and the
  470. /// corresponding integral exponent of two in exp, returning:
  471. /// significand * exp(2, exponent)
  472. ///
  473. /// If this product is too large to be represented in the
  474. /// floating-point type, the result is undefined.
  475. ///
  476. /// @tparam genType Floating-point scalar or vector types.
  477. ///
  478. /// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/ldexp.xml">GLSL ldexp man page</a>;
  479. /// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.3 Common Functions</a>
  480. template<typename genType>
  481. GLM_FUNC_DECL genType ldexp(genType const& x, int const& exp);
  482. template<length_t L, typename T, qualifier Q>
  483. GLM_FUNC_DECL vec<L, T, Q> ldexp(vec<L, T, Q> const& v, vec<L, int, Q> const& exp);
  484. /// @}
  485. }//namespace glm
  486. #include "detail/func_common.inl"