mirror of
https://github.com/BlackMATov/vmath.hpp.git
synced 2025-12-13 04:06:52 +07:00
add constexpr for scalar ops for future standards
This commit is contained in:
@@ -150,49 +150,49 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
floor(T x) noexcept {
|
||||
constexpr floor(T x) noexcept {
|
||||
return std::floor(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
trunc(T x) noexcept {
|
||||
constexpr trunc(T x) noexcept {
|
||||
return std::trunc(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
round(T x) noexcept {
|
||||
constexpr round(T x) noexcept {
|
||||
return std::round(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
ceil(T x) noexcept {
|
||||
constexpr ceil(T x) noexcept {
|
||||
return std::ceil(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
fract(T x) noexcept {
|
||||
constexpr fract(T x) noexcept {
|
||||
return x - floor(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
fmod(T x, T y) noexcept {
|
||||
constexpr fmod(T x, T y) noexcept {
|
||||
return std::fmod(x, y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
modf(T x, T* y) noexcept {
|
||||
constexpr modf(T x, T* y) noexcept {
|
||||
return std::modf(x, y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
copysign(T x, T s) noexcept {
|
||||
constexpr copysign(T x, T s) noexcept {
|
||||
return std::copysign(x, s);
|
||||
}
|
||||
|
||||
@@ -266,91 +266,91 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
sin(T x) noexcept {
|
||||
constexpr sin(T x) noexcept {
|
||||
return std::sin(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
cos(T x) noexcept {
|
||||
constexpr cos(T x) noexcept {
|
||||
return std::cos(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
tan(T x) noexcept {
|
||||
constexpr tan(T x) noexcept {
|
||||
return std::tan(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
asin(T x) noexcept {
|
||||
constexpr asin(T x) noexcept {
|
||||
return std::asin(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
acos(T x) noexcept {
|
||||
constexpr acos(T x) noexcept {
|
||||
return std::acos(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
atan(T x) noexcept {
|
||||
constexpr atan(T x) noexcept {
|
||||
return std::atan(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
atan2(T y, T x) noexcept {
|
||||
constexpr atan2(T y, T x) noexcept {
|
||||
return std::atan2(y, x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
sinh(T x) noexcept {
|
||||
constexpr sinh(T x) noexcept {
|
||||
return std::sinh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
cosh(T x) noexcept {
|
||||
constexpr cosh(T x) noexcept {
|
||||
return std::cosh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
tanh(T x) noexcept {
|
||||
constexpr tanh(T x) noexcept {
|
||||
return std::tanh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
asinh(T x) noexcept {
|
||||
constexpr asinh(T x) noexcept {
|
||||
return std::asinh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
acosh(T x) noexcept {
|
||||
constexpr acosh(T x) noexcept {
|
||||
return std::acosh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
atanh(T x) noexcept {
|
||||
constexpr atanh(T x) noexcept {
|
||||
return std::atanh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, std::pair<T, T>>
|
||||
sincos(T x) noexcept {
|
||||
constexpr sincos(T x) noexcept {
|
||||
return { sin(x), cos(x) };
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
std::enable_if_t<std::is_floating_point_v<T>, void>
|
||||
sincos(T x, T* s, T* c) noexcept {
|
||||
constexpr sincos(T x, T* s, T* c) noexcept {
|
||||
*s = sin(x);
|
||||
*c = cos(x);
|
||||
}
|
||||
@@ -364,43 +364,43 @@ namespace vmath_hpp
|
||||
{
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
pow(T x, T y) noexcept {
|
||||
constexpr pow(T x, T y) noexcept {
|
||||
return std::pow(x, y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
exp(T x) noexcept {
|
||||
constexpr exp(T x) noexcept {
|
||||
return std::exp(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
log(T x) noexcept {
|
||||
constexpr log(T x) noexcept {
|
||||
return std::log(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
exp2(T x) noexcept {
|
||||
constexpr exp2(T x) noexcept {
|
||||
return std::exp2(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
log2(T x) noexcept {
|
||||
constexpr log2(T x) noexcept {
|
||||
return std::log2(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
sqrt(T x) noexcept {
|
||||
constexpr sqrt(T x) noexcept {
|
||||
return std::sqrt(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
rsqrt(T x) noexcept {
|
||||
constexpr rsqrt(T x) noexcept {
|
||||
return rcp(sqrt(x));
|
||||
}
|
||||
}
|
||||
@@ -483,7 +483,7 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
refract(T i, T n, T eta) noexcept {
|
||||
constexpr refract(T i, T n, T eta) noexcept {
|
||||
const T d = dot(n, i);
|
||||
const T k = T{1} - sqr(eta) * (T{1} - sqr(d));
|
||||
return k < T{0} ? T{0} : (eta * i - (eta * d + sqrt(k)) * n);
|
||||
|
||||
@@ -44,49 +44,49 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
floor(T x) noexcept {
|
||||
constexpr floor(T x) noexcept {
|
||||
return std::floor(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
trunc(T x) noexcept {
|
||||
constexpr trunc(T x) noexcept {
|
||||
return std::trunc(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
round(T x) noexcept {
|
||||
constexpr round(T x) noexcept {
|
||||
return std::round(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
ceil(T x) noexcept {
|
||||
constexpr ceil(T x) noexcept {
|
||||
return std::ceil(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
fract(T x) noexcept {
|
||||
constexpr fract(T x) noexcept {
|
||||
return x - floor(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
fmod(T x, T y) noexcept {
|
||||
constexpr fmod(T x, T y) noexcept {
|
||||
return std::fmod(x, y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
modf(T x, T* y) noexcept {
|
||||
constexpr modf(T x, T* y) noexcept {
|
||||
return std::modf(x, y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
copysign(T x, T s) noexcept {
|
||||
constexpr copysign(T x, T s) noexcept {
|
||||
return std::copysign(x, s);
|
||||
}
|
||||
|
||||
@@ -160,91 +160,91 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
sin(T x) noexcept {
|
||||
constexpr sin(T x) noexcept {
|
||||
return std::sin(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
cos(T x) noexcept {
|
||||
constexpr cos(T x) noexcept {
|
||||
return std::cos(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
tan(T x) noexcept {
|
||||
constexpr tan(T x) noexcept {
|
||||
return std::tan(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
asin(T x) noexcept {
|
||||
constexpr asin(T x) noexcept {
|
||||
return std::asin(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
acos(T x) noexcept {
|
||||
constexpr acos(T x) noexcept {
|
||||
return std::acos(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
atan(T x) noexcept {
|
||||
constexpr atan(T x) noexcept {
|
||||
return std::atan(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
atan2(T y, T x) noexcept {
|
||||
constexpr atan2(T y, T x) noexcept {
|
||||
return std::atan2(y, x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
sinh(T x) noexcept {
|
||||
constexpr sinh(T x) noexcept {
|
||||
return std::sinh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
cosh(T x) noexcept {
|
||||
constexpr cosh(T x) noexcept {
|
||||
return std::cosh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
tanh(T x) noexcept {
|
||||
constexpr tanh(T x) noexcept {
|
||||
return std::tanh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
asinh(T x) noexcept {
|
||||
constexpr asinh(T x) noexcept {
|
||||
return std::asinh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
acosh(T x) noexcept {
|
||||
constexpr acosh(T x) noexcept {
|
||||
return std::acosh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
atanh(T x) noexcept {
|
||||
constexpr atanh(T x) noexcept {
|
||||
return std::atanh(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, std::pair<T, T>>
|
||||
sincos(T x) noexcept {
|
||||
constexpr sincos(T x) noexcept {
|
||||
return { sin(x), cos(x) };
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
std::enable_if_t<std::is_floating_point_v<T>, void>
|
||||
sincos(T x, T* s, T* c) noexcept {
|
||||
constexpr sincos(T x, T* s, T* c) noexcept {
|
||||
*s = sin(x);
|
||||
*c = cos(x);
|
||||
}
|
||||
@@ -258,43 +258,43 @@ namespace vmath_hpp
|
||||
{
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
pow(T x, T y) noexcept {
|
||||
constexpr pow(T x, T y) noexcept {
|
||||
return std::pow(x, y);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
exp(T x) noexcept {
|
||||
constexpr exp(T x) noexcept {
|
||||
return std::exp(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
log(T x) noexcept {
|
||||
constexpr log(T x) noexcept {
|
||||
return std::log(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
exp2(T x) noexcept {
|
||||
constexpr exp2(T x) noexcept {
|
||||
return std::exp2(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
log2(T x) noexcept {
|
||||
constexpr log2(T x) noexcept {
|
||||
return std::log2(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
sqrt(T x) noexcept {
|
||||
constexpr sqrt(T x) noexcept {
|
||||
return std::sqrt(x);
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
rsqrt(T x) noexcept {
|
||||
constexpr rsqrt(T x) noexcept {
|
||||
return rcp(sqrt(x));
|
||||
}
|
||||
}
|
||||
@@ -377,7 +377,7 @@ namespace vmath_hpp
|
||||
|
||||
template < typename T >
|
||||
[[nodiscard]] std::enable_if_t<std::is_floating_point_v<T>, T>
|
||||
refract(T i, T n, T eta) noexcept {
|
||||
constexpr refract(T i, T n, T eta) noexcept {
|
||||
const T d = dot(n, i);
|
||||
const T k = T{1} - sqr(eta) * (T{1} - sqr(d));
|
||||
return k < T{0} ? T{0} : (eta * i - (eta * d + sqrt(k)) * n);
|
||||
|
||||
Reference in New Issue
Block a user