scalar_common.inl 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. namespace glm
  2. {
  3. template<typename T>
  4. GLM_FUNC_QUALIFIER T min(T a, T b, T c)
  5. {
  6. return glm::min(glm::min(a, b), c);
  7. }
  8. template<typename T>
  9. GLM_FUNC_QUALIFIER T min(T a, T b, T c, T d)
  10. {
  11. return glm::min(glm::min(a, b), glm::min(c, d));
  12. }
  13. template<typename T>
  14. GLM_FUNC_QUALIFIER T max(T a, T b, T c)
  15. {
  16. return glm::max(glm::max(a, b), c);
  17. }
  18. template<typename T>
  19. GLM_FUNC_QUALIFIER T max(T a, T b, T c, T d)
  20. {
  21. return glm::max(glm::max(a, b), glm::max(c, d));
  22. }
  23. # if GLM_HAS_CXX11_STL
  24. using std::fmin;
  25. # else
  26. template<typename T>
  27. GLM_FUNC_QUALIFIER T fmin(T a, T b)
  28. {
  29. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'fmin' only accept floating-point input");
  30. if (isnan(a))
  31. return b;
  32. return min(a, b);
  33. }
  34. # endif
  35. template<typename T>
  36. GLM_FUNC_QUALIFIER T fmin(T a, T b, T c)
  37. {
  38. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'fmin' only accept floating-point input");
  39. if (isnan(a))
  40. return fmin(b, c);
  41. if (isnan(b))
  42. return fmin(a, c);
  43. if (isnan(c))
  44. return min(a, b);
  45. return min(a, b, c);
  46. }
  47. template<typename T>
  48. GLM_FUNC_QUALIFIER T fmin(T a, T b, T c, T d)
  49. {
  50. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'fmin' only accept floating-point input");
  51. if (isnan(a))
  52. return fmin(b, c, d);
  53. if (isnan(b))
  54. return min(a, fmin(c, d));
  55. if (isnan(c))
  56. return fmin(min(a, b), d);
  57. if (isnan(d))
  58. return min(a, b, c);
  59. return min(a, b, c, d);
  60. }
  61. # if GLM_HAS_CXX11_STL
  62. using std::fmax;
  63. # else
  64. template<typename T>
  65. GLM_FUNC_QUALIFIER T fmax(T a, T b)
  66. {
  67. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'fmax' only accept floating-point input");
  68. if (isnan(a))
  69. return b;
  70. return max(a, b);
  71. }
  72. # endif
  73. template<typename T>
  74. GLM_FUNC_QUALIFIER T fmax(T a, T b, T c)
  75. {
  76. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'fmax' only accept floating-point input");
  77. if (isnan(a))
  78. return fmax(b, c);
  79. if (isnan(b))
  80. return fmax(a, c);
  81. if (isnan(c))
  82. return max(a, b);
  83. return max(a, b, c);
  84. }
  85. template<typename T>
  86. GLM_FUNC_QUALIFIER T fmax(T a, T b, T c, T d)
  87. {
  88. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'fmax' only accept floating-point input");
  89. if (isnan(a))
  90. return fmax(b, c, d);
  91. if (isnan(b))
  92. return max(a, fmax(c, d));
  93. if (isnan(c))
  94. return fmax(max(a, b), d);
  95. if (isnan(d))
  96. return max(a, b, c);
  97. return max(a, b, c, d);
  98. }
  99. }//namespace glm