5#include "compute_common.hpp"
10#include "_vectorize.hpp"
16 template<
typename genType>
17 GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType
min(genType x, genType y)
19 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer,
"'min' only accept floating-point or integer inputs");
20 return (y < x) ? y : x;
24 template<
typename genType>
25 GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType
max(genType x, genType y)
27 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer,
"'max' only accept floating-point or integer inputs");
29 return (x < y) ? y : x;
34 GLM_FUNC_QUALIFIER GLM_CONSTEXPR
int abs(
int x)
36 int const y = x >> (
sizeof(int) * 8 - 1);
44 template<
typename genType>
45 GLM_FUNC_QUALIFIER genType
round(genType x)
47 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559,
"'round' only accept floating-point inputs");
49 return x < static_cast<genType>(0) ?
static_cast<genType
>(int(x -
static_cast<genType
>(0.5))) : static_cast<genType>(int(x + static_cast<genType>(0.5)));
57 template<
typename genType>
58 GLM_FUNC_QUALIFIER genType
trunc(genType x)
60 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559,
"'trunc' only accept floating-point inputs");
62 return x < static_cast<genType>(0) ? -std::floor(-x) : std::
floor(x);
71 template<length_t L,
typename T, qualifier Q,
bool Aligned>
80 template<length_t L,
typename T,
typename U, qualifier Q,
bool Aligned>
83 GLM_FUNC_QUALIFIER
static vec<L, T, Q> call(
vec<L, T, Q> const& x,
vec<L, T, Q> const& y,
vec<L, U, Q> const& a)
85 GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE,
"'mix' only accept floating-point inputs for the interpolator a");
91 template<length_t L,
typename T, qualifier Q,
bool Aligned>
94 GLM_FUNC_QUALIFIER
static vec<L, T, Q> call(
vec<L, T, Q> const& x,
vec<L, T, Q> const& y,
vec<L, bool, Q> const& a)
97 for(length_t i = 0; i < x.length(); ++i)
98 Result[i] = a[i] ? y[i] : x[i];
103 template<length_t L,
typename T,
typename U, qualifier Q,
bool Aligned>
108 GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE,
"'mix' only accept floating-point inputs for the interpolator a");
114 template<length_t L,
typename T, qualifier Q,
bool Aligned>
123 template<
typename T,
typename U>
126 GLM_FUNC_QUALIFIER
static T call(T
const& x, T
const& y, U
const& a)
128 GLM_STATIC_ASSERT(std::numeric_limits<U>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE,
"'mix' only accept floating-point inputs for the interpolator a");
130 return static_cast<T
>(
static_cast<U
>(x) * (
static_cast<U
>(1) - a) +
static_cast<U
>(y) * a);
137 GLM_FUNC_QUALIFIER
static T call(T
const& x, T
const& y,
bool const& a)
143 template<length_t L,
typename T, qualifier Q,
bool isFloat,
bool Aligned>
148 return vec<L, T, Q>(
glm::lessThan(
vec<L, T, Q>(0), x)) -
vec<L, T, Q>(
glm::lessThan(x,
vec<L, T, Q>(0)));
152# if GLM_ARCH == GLM_ARCH_X86
153 template<length_t L,
typename T, qualifier Q,
bool Aligned>
158 T
const Shift(
static_cast<T
>(
sizeof(T) * 8 - 1));
161 return (x >> Shift) | y;
166 template<length_t L,
typename T, qualifier Q,
bool Aligned>
175 template<length_t L,
typename T, qualifier Q,
bool Aligned>
184 template<length_t L,
typename T, qualifier Q,
bool Aligned>
193 template<length_t L,
typename T, qualifier Q,
bool Aligned>
202 template<length_t L,
typename T, qualifier Q,
bool Aligned>
211 template<length_t L,
typename T, qualifier Q,
bool Aligned>
216 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'mod' only accept floating-point inputs. Include <glm/gtc/integer.hpp> for integer inputs.");
217 return a - b *
floor(a / b);
221 template<length_t L,
typename T, qualifier Q,
bool Aligned>
230 template<length_t L,
typename T, qualifier Q,
bool Aligned>
239 template<length_t L,
typename T, qualifier Q,
bool Aligned>
242 GLM_FUNC_QUALIFIER
static vec<L, T, Q> call(
vec<L, T, Q> const& x,
vec<L, T, Q> const& minVal,
vec<L, T, Q> const& maxVal)
244 return min(
max(x, minVal), maxVal);
248 template<length_t L,
typename T, qualifier Q,
bool Aligned>
257 template<length_t L,
typename T, qualifier Q,
bool Aligned>
260 GLM_FUNC_QUALIFIER
static vec<L, T, Q> call(
vec<L, T, Q> const& edge0,
vec<L, T, Q> const& edge1,
vec<L, T, Q> const& x)
262 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE,
"'smoothstep' only accept floating-point inputs");
263 vec<L, T, Q> const tmp(clamp((x - edge0) / (edge1 - edge0),
static_cast<T
>(0),
static_cast<T
>(1)));
264 return tmp * tmp * (
static_cast<T
>(3) -
static_cast<T
>(2) * tmp);
269 template<
typename genFIType>
270 GLM_FUNC_QUALIFIER GLM_CONSTEXPR genFIType
abs(genFIType x)
275 template<length_t L,
typename T, qualifier Q>
283 template<
typename genFIType>
284 GLM_FUNC_QUALIFIER genFIType
sign(genFIType x)
287 std::numeric_limits<genFIType>::is_iec559 || (std::numeric_limits<genFIType>::is_signed && std::numeric_limits<genFIType>::is_integer),
288 "'sign' only accept signed inputs");
290 return detail::compute_sign<1, genFIType, defaultp,
291 std::numeric_limits<genFIType>::is_iec559, detail::is_aligned<highp>::value>::call(vec<1, genFIType>(x)).x;
294 template<length_t L,
typename T, qualifier Q>
298 std::numeric_limits<T>::is_iec559 || (std::numeric_limits<T>::is_signed && std::numeric_limits<T>::is_integer),
299 "'sign' only accept signed inputs");
306 template<length_t L,
typename T, qualifier Q>
309 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'floor' only accept floating-point inputs.");
313 template<length_t L,
typename T, qualifier Q>
316 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'trunc' only accept floating-point inputs");
320 template<length_t L,
typename T, qualifier Q>
323 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'round' only accept floating-point inputs");
339 template<
typename genType>
340 GLM_FUNC_QUALIFIER genType
roundEven(genType x)
342 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559,
"'roundEven' only accept floating-point inputs");
344 int Integer =
static_cast<int>(x);
345 genType IntegerPart =
static_cast<genType
>(Integer);
346 genType FractionalPart =
fract(x);
348 if(FractionalPart >
static_cast<genType
>(0.5) || FractionalPart <
static_cast<genType
>(0.5))
352 else if((Integer % 2) == 0)
356 else if(x <=
static_cast<genType
>(0))
358 return IntegerPart -
static_cast<genType
>(1);
362 return IntegerPart +
static_cast<genType
>(1);
370 template<length_t L,
typename T, qualifier Q>
373 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'roundEven' only accept floating-point inputs");
379 template<length_t L,
typename T, qualifier Q>
382 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'ceil' only accept floating-point inputs");
387 template<
typename genType>
388 GLM_FUNC_QUALIFIER genType
fract(genType x)
393 template<length_t L,
typename T, qualifier Q>
396 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'fract' only accept floating-point inputs");
401 template<
typename genType>
402 GLM_FUNC_QUALIFIER genType mod(genType x, genType y)
404# if GLM_COMPILER & GLM_COMPILER_CUDA
406 vec<1, genType, defaultp> Result(mod(vec<1, genType, defaultp>(x), y));
409 return mod(vec<1, genType, defaultp>(x), y).x;
413 template<length_t L,
typename T, qualifier Q>
414 GLM_FUNC_QUALIFIER vec<L, T, Q> mod(vec<L, T, Q>
const& x, T y)
416 return detail::compute_mod<L, T, Q, detail::is_aligned<Q>::value>::call(x, vec<L, T, Q>(y));
419 template<length_t L,
typename T, qualifier Q>
426 template<
typename genType>
427 GLM_FUNC_QUALIFIER genType
modf(genType x, genType & i)
429 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559,
"'modf' only accept floating-point inputs");
430 return std::modf(x, &i);
433 template<
typename T, qualifier Q>
434 GLM_FUNC_QUALIFIER vec<1, T, Q>
modf(vec<1, T, Q>
const& x, vec<1, T, Q> & i)
440 template<
typename T, qualifier Q>
441 GLM_FUNC_QUALIFIER vec<2, T, Q>
modf(vec<2, T, Q>
const& x, vec<2, T, Q> & i)
448 template<
typename T, qualifier Q>
449 GLM_FUNC_QUALIFIER vec<3, T, Q>
modf(vec<3, T, Q>
const& x, vec<3, T, Q> & i)
457 template<
typename T, qualifier Q>
458 GLM_FUNC_QUALIFIER vec<4, T, Q>
modf(vec<4, T, Q>
const& x, vec<4, T, Q> & i)
476 template<length_t L,
typename T, qualifier Q>
479 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
"'min' only accept floating-point or integer inputs");
483 template<length_t L,
typename T, qualifier Q>
490 template<length_t L,
typename T, qualifier Q>
493 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
"'max' only accept floating-point or integer inputs");
497 template<length_t L,
typename T, qualifier Q>
504 template<
typename genType>
505 GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType clamp(genType x, genType minVal, genType maxVal)
507 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || std::numeric_limits<genType>::is_integer,
"'clamp' only accept floating-point or integer inputs");
508 return min(
max(x, minVal), maxVal);
511 template<length_t L,
typename T, qualifier Q>
514 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
"'clamp' only accept floating-point or integer inputs");
518 template<length_t L,
typename T, qualifier Q>
519 GLM_FUNC_QUALIFIER 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)
521 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559 || std::numeric_limits<T>::is_integer,
"'clamp' only accept floating-point or integer inputs");
525 template<
typename genTypeT,
typename genTypeU>
526 GLM_FUNC_QUALIFIER genTypeT
mix(genTypeT x, genTypeT y, genTypeU a)
531 template<length_t L,
typename T,
typename U, qualifier Q>
532 GLM_FUNC_QUALIFIER vec<L, T, Q>
mix(vec<L, T, Q>
const& x, vec<L, T, Q>
const& y, U a)
534 return detail::compute_mix_scalar<L, T, U, Q, detail::is_aligned<Q>::value>::call(x, y, a);
537 template<length_t L,
typename T,
typename U, qualifier Q>
538 GLM_FUNC_QUALIFIER vec<L, T, Q>
mix(vec<L, T, Q>
const& x, vec<L, T, Q>
const& y, vec<L, U, Q>
const& a)
540 return detail::compute_mix_vector<L, T, U, Q, detail::is_aligned<Q>::value>::call(x, y, a);
544 template<
typename genType>
545 GLM_FUNC_QUALIFIER genType
step(genType edge, genType x)
547 return mix(
static_cast<genType
>(1),
static_cast<genType
>(0), x < edge);
550 template<length_t L,
typename T, qualifier Q>
556 template<length_t L,
typename T, qualifier Q>
563 template<
typename genType>
564 GLM_FUNC_QUALIFIER genType
smoothstep(genType edge0, genType edge1, genType x)
566 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559 || GLM_CONFIG_UNRESTRICTED_GENTYPE,
"'smoothstep' only accept floating-point inputs");
568 genType
const tmp(clamp((x - edge0) / (edge1 - edge0), genType(0), genType(1)));
569 return tmp * tmp * (genType(3) - genType(2) * tmp);
572 template<length_t L,
typename T, qualifier Q>
573 GLM_FUNC_QUALIFIER vec<L, T, Q>
smoothstep(T edge0, T edge1, vec<L, T, Q>
const& x)
575 return detail::compute_smoothstep_vector<L, T, Q, detail::is_aligned<Q>::value>::call(vec<L, T, Q>(edge0), vec<L, T, Q>(edge1), x);
578 template<length_t L,
typename T, qualifier Q>
579 GLM_FUNC_QUALIFIER vec<L, T, Q>
smoothstep(vec<L, T, Q>
const& edge0, vec<L, T, Q>
const& edge1, vec<L, T, Q>
const& x)
581 return detail::compute_smoothstep_vector<L, T, Q, detail::is_aligned<Q>::value>::call(edge0, edge1, x);
584# if GLM_HAS_CXX11_STL
587 template<
typename genType>
588 GLM_FUNC_QUALIFIER
bool isnan(genType x)
590 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559,
"'isnan' only accept floating-point inputs");
592# if GLM_HAS_CXX11_STL
593 return std::isnan(x);
594# elif GLM_COMPILER & GLM_COMPILER_VC
595 return _isnan(x) != 0;
596# elif GLM_COMPILER & GLM_COMPILER_INTEL
597# if GLM_PLATFORM & GLM_PLATFORM_WINDOWS
598 return _isnan(x) != 0;
600 return ::isnan(x) != 0;
602# elif (GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)) && (GLM_PLATFORM & GLM_PLATFORM_ANDROID) && __cplusplus < 201103L
603 return _isnan(x) != 0;
604# elif GLM_COMPILER & GLM_COMPILER_CUDA
605 return ::isnan(x) != 0;
607 return std::isnan(x);
612 template<length_t L,
typename T, qualifier Q>
615 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'isnan' only accept floating-point inputs");
618 for (length_t l = 0; l < v.length(); ++l)
623# if GLM_HAS_CXX11_STL
626 template<
typename genType>
627 GLM_FUNC_QUALIFIER
bool isinf(genType x)
629 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559,
"'isinf' only accept floating-point inputs");
631# if GLM_HAS_CXX11_STL
632 return std::isinf(x);
633# elif GLM_COMPILER & (GLM_COMPILER_INTEL | GLM_COMPILER_VC)
634# if(GLM_PLATFORM & GLM_PLATFORM_WINDOWS)
635 return _fpclass(x) == _FPCLASS_NINF || _fpclass(x) == _FPCLASS_PINF;
639# elif GLM_COMPILER & (GLM_COMPILER_GCC | GLM_COMPILER_CLANG)
640# if(GLM_PLATFORM & GLM_PLATFORM_ANDROID && __cplusplus < 201103L)
641 return _isinf(x) != 0;
643 return std::isinf(x);
645# elif GLM_COMPILER & GLM_COMPILER_CUDA
647 return ::isinf(
double(x)) != 0;
649 return std::isinf(x);
654 template<length_t L,
typename T, qualifier Q>
657 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'isinf' only accept floating-point inputs");
660 for (length_t l = 0; l < v.length(); ++l)
678 template<length_t L, qualifier Q>
697 template<length_t L, qualifier Q>
716 template<length_t L, qualifier Q>
735 template<length_t L, qualifier Q>
741# if GLM_HAS_CXX11_STL
744 template<
typename genType>
745 GLM_FUNC_QUALIFIER genType
fma(genType
const& a, genType
const& b, genType
const& c)
751 template<
typename genType>
752 GLM_FUNC_QUALIFIER genType
frexp(genType x,
int& exp)
754 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559,
"'frexp' only accept floating-point inputs");
756 return std::frexp(x, &exp);
759 template<length_t L,
typename T, qualifier Q>
760 GLM_FUNC_QUALIFIER vec<L, T, Q>
frexp(vec<L, T, Q>
const& v, vec<L, int, Q>& exp)
762 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'frexp' only accept floating-point inputs");
765 for (length_t l = 0; l < v.length(); ++l)
766 Result[l] = std::frexp(v[l], &exp[l]);
770 template<
typename genType>
771 GLM_FUNC_QUALIFIER genType
ldexp(genType
const& x,
int const& exp)
773 GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559,
"'ldexp' only accept floating-point inputs");
775 return std::ldexp(x, exp);
778 template<length_t L,
typename T, qualifier Q>
779 GLM_FUNC_QUALIFIER vec<L, T, Q>
ldexp(vec<L, T, Q>
const& v, vec<L, int, Q>
const& exp)
781 GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559,
"'ldexp' only accept floating-point inputs");
784 for (length_t l = 0; l < v.length(); ++l)
785 Result[l] = std::ldexp(v[l], exp[l]);
790#if GLM_CONFIG_SIMD == GLM_ENABLE
GLM_FUNC_DECL genType step(genType edge, genType x)
Definition func_common.inl:545
GLM_FUNC_DECL float intBitsToFloat(int const &v)
Definition func_common.inl:703
GLM_FUNC_DECL vec< L, T, Q > trunc(vec< L, T, Q > const &x)
Definition func_common.inl:314
GLM_FUNC_DECL GLM_CONSTEXPR genType abs(genType x)
GLM_FUNC_DECL genType smoothstep(genType edge0, genType edge1, genType x)
Definition func_common.inl:564
GLM_FUNC_DECL vec< L, T, Q > roundEven(vec< L, T, Q > const &x)
Definition func_common.inl:371
GLM_FUNC_DECL GLM_CONSTEXPR genType min(genType x, genType y)
Definition func_common.inl:17
GLM_FUNC_DECL vec< L, bool, Q > isinf(vec< L, T, Q > const &x)
Definition func_common.inl:655
GLM_FUNC_DECL uint floatBitsToUint(float const &v)
Definition func_common.inl:684
GLM_FUNC_DECL vec< L, T, Q > ceil(vec< L, T, Q > const &x)
Definition func_common.inl:380
GLM_FUNC_DECL vec< L, bool, Q > isnan(vec< L, T, Q > const &x)
Definition func_common.inl:613
GLM_FUNC_DECL genType modf(genType x, genType &i)
Definition func_common.inl:427
GLM_FUNC_DECL genType fract(genType x)
Definition func_common.inl:388
GLM_FUNC_DECL genTypeT mix(genTypeT x, genTypeT y, genTypeU a)
Definition func_common.inl:526
GLM_FUNC_DECL float uintBitsToFloat(uint const &v)
Definition func_common.inl:722
GLM_FUNC_DECL vec< L, T, Q > round(vec< L, T, Q > const &x)
Definition func_common.inl:321
GLM_FUNC_DECL genType ldexp(genType const &x, int const &exp)
Definition func_common.inl:771
GLM_FUNC_DECL vec< L, T, Q > floor(vec< L, T, Q > const &x)
Definition func_common.inl:307
GLM_FUNC_DECL genType fma(genType const &a, genType const &b, genType const &c)
Definition func_common.inl:745
GLM_FUNC_DECL int floatBitsToInt(float const &v)
Definition func_common.inl:665
GLM_FUNC_DECL genType frexp(genType x, int &exp)
Definition func_common.inl:752
GLM_FUNC_DECL GLM_CONSTEXPR genType max(genType x, genType y)
Definition func_common.inl:25
GLM_FUNC_DECL vec< L, T, Q > sign(vec< L, T, Q > const &x)
Definition func_common.inl:295
GLM_FUNC_QUALIFIER GLM_CONSTEXPR vec< L, bool, Q > lessThan(vec< L, T, Q > const &x, vec< L, T, Q > const &y)
Definition func_vector_relational.inl:4
detail namespace with internal helper functions
Definition json.h:249
Core features
Definition common.hpp:21
Definition func_common.inl:73
Definition compute_common.hpp:11
Definition func_common.inl:177
Definition func_common.inl:241
Definition func_common.inl:168
Definition func_common.inl:186
Definition func_common.inl:232
Definition func_common.inl:223
Definition func_common.inl:105
Definition func_common.inl:82
Definition func_common.inl:125
Definition func_common.inl:213
Definition func_common.inl:204
Definition func_common.inl:145
Definition func_common.inl:259
Definition func_common.inl:250
Definition func_common.inl:195
Definition _vectorize.hpp:7
Definition _vectorize.hpp:46
Definition qualifier.hpp:60
Definition qualifier.hpp:35