func_common.hpp 27 KB

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