diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-08-21 17:40:38 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2018-08-21 17:40:38 +0200 |
commit | 2877f4eda3d1b0c7431039e3142ecf1a282a34b1 (patch) | |
tree | 58ad35e27ab2a3b8955f5adbf28f296670681ffc /external/include/glm/gtc/ulp.inl | |
parent | Smooth sun movement (diff) | |
download | AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.gz AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.bz2 AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.lz AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.xz AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.tar.zst AltCraft-2877f4eda3d1b0c7431039e3142ecf1a282a34b1.zip |
Diffstat (limited to '')
-rw-r--r-- | external/include/glm/gtc/ulp.inl | 136 |
1 files changed, 77 insertions, 59 deletions
diff --git a/external/include/glm/gtc/ulp.inl b/external/include/glm/gtc/ulp.inl index 54c914a..620be36 100644 --- a/external/include/glm/gtc/ulp.inl +++ b/external/include/glm/gtc/ulp.inl @@ -9,6 +9,7 @@ /// is preserved. #include "../detail/type_int.hpp" +#include "epsilon.hpp" #include <cmath> #include <cfloat> #include <limits> @@ -78,33 +79,42 @@ namespace detail ix = hx&0x7fffffff; // |x| iy = hy&0x7fffffff; // |y| - if((ix>0x7f800000) || // x is nan - (iy>0x7f800000)) // y is nan + if((ix>0x7f800000) || // x is nan + (iy>0x7f800000)) // y is nan return x+y; - if(x==y) return y; // x=y, return y - if(ix==0) { // x == 0 + if(compute_equal<float>::call(x, y)) + return y; // x=y, return y + if(ix==0) + { // x == 0 GLM_SET_FLOAT_WORD(x,(hy&0x80000000)|1);// return +-minsubnormal t = x*x; - if(t==x) return t; else return x; // raise underflow flag + if(detail::compute_equal<float>::call(t, x)) + return t; + else + return x; // raise underflow flag } - if(hx>=0) { // x > 0 - if(hx>hy) { // x > y, x -= ulp + if(hx>=0) + { // x > 0 + if(hx>hy) // x > y, x -= ulp hx -= 1; - } else { // x < y, x += ulp + else // x < y, x += ulp hx += 1; - } - } else { // x < 0 - if(hy>=0||hx>hy){ // x < y, x -= ulp + } + else + { // x < 0 + if(hy>=0||hx>hy) // x < y, x -= ulp hx -= 1; - } else { // x > y, x += ulp + else // x > y, x += ulp hx += 1; - } } hy = hx&0x7f800000; - if(hy>=0x7f800000) return x+x; // overflow - if(hy<0x00800000) { // underflow + if(hy>=0x7f800000) + return x+x; // overflow + if(hy<0x00800000) // underflow + { t = x*x; - if(t!=x) { // raise underflow flag + if(!detail::compute_equal<float>::call(t, x)) + { // raise underflow flag GLM_SET_FLOAT_WORD(y,hx); return y; } @@ -121,27 +131,32 @@ namespace detail GLM_EXTRACT_WORDS(hx, lx, x); GLM_EXTRACT_WORDS(hy, ly, y); - ix = hx & 0x7fffffff; // |x| - iy = hy & 0x7fffffff; // |y| + ix = hx & 0x7fffffff; // |x| + iy = hy & 0x7fffffff; // |y| - if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || // x is nan - ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) // y is nan + if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || // x is nan + ((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) // y is nan return x+y; - if(x==y) return y; // x=y, return y - if((ix|lx)==0) { // x == 0 - GLM_INSERT_WORDS(x, hy & 0x80000000, 1); // return +-minsubnormal + if(detail::compute_equal<double>::call(x, y)) + return y; // x=y, return y + if((ix|lx)==0) + { // x == 0 + GLM_INSERT_WORDS(x, hy & 0x80000000, 1); // return +-minsubnormal t = x*x; - if(t==x) return t; else return x; // raise underflow flag + if(detail::compute_equal<double>::call(t, x)) + return t; + else + return x; // raise underflow flag } - if(hx>=0) { // x > 0 - if(hx>hy||((hx==hy)&&(lx>ly))) { // x > y, x -= ulp + if(hx>=0) { // x > 0 + if(hx>hy||((hx==hy)&&(lx>ly))) { // x > y, x -= ulp if(lx==0) hx -= 1; lx -= 1; } else { // x < y, x += ulp lx += 1; if(lx==0) hx += 1; } - } else { // x < 0 + } else { // x < 0 if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){// x < y, x -= ulp if(lx==0) hx -= 1; lx -= 1; @@ -151,10 +166,13 @@ namespace detail } } hy = hx&0x7ff00000; - if(hy>=0x7ff00000) return x+x; // overflow - if(hy<0x00100000) { // underflow + if(hy>=0x7ff00000) + return x+x; // overflow + if(hy<0x00100000) + { // underflow t = x*x; - if(t!=x) { // raise underflow flag + if(!detail::compute_equal<double>::call(t, x)) + { // raise underflow flag GLM_INSERT_WORDS(y,hx,lx); return y; } @@ -171,8 +189,8 @@ namespace detail namespace glm { - template <> - GLM_FUNC_QUALIFIER float next_float(float const & x) + template<> + GLM_FUNC_QUALIFIER float next_float(float const& x) { # if GLM_HAS_CXX11_STL return std::nextafter(x, std::numeric_limits<float>::max()); @@ -185,8 +203,8 @@ namespace glm # endif } - template <> - GLM_FUNC_QUALIFIER double next_float(double const & x) + template<> + GLM_FUNC_QUALIFIER double next_float(double const& x) { # if GLM_HAS_CXX11_STL return std::nextafter(x, std::numeric_limits<double>::max()); @@ -199,16 +217,16 @@ namespace glm # endif } - template<typename T, precision P, template<typename, precision> class vecType> - GLM_FUNC_QUALIFIER vecType<T, P> next_float(vecType<T, P> const & x) + template<length_t L, typename T, qualifier Q> + GLM_FUNC_QUALIFIER vec<L, T, Q> next_float(vec<L, T, Q> const& x) { - vecType<T, P> Result(uninitialize); + vec<L, T, Q> Result; for(length_t i = 0, n = Result.length(); i < n; ++i) Result[i] = next_float(x[i]); return Result; } - GLM_FUNC_QUALIFIER float prev_float(float const & x) + GLM_FUNC_QUALIFIER float prev_float(float const& x) { # if GLM_HAS_CXX11_STL return std::nextafter(x, std::numeric_limits<float>::min()); @@ -221,7 +239,7 @@ namespace glm # endif } - GLM_FUNC_QUALIFIER double prev_float(double const & x) + GLM_FUNC_QUALIFIER double prev_float(double const& x) { # if GLM_HAS_CXX11_STL return std::nextafter(x, std::numeric_limits<double>::min()); @@ -234,17 +252,17 @@ namespace glm # endif } - template<typename T, precision P, template<typename, precision> class vecType> - GLM_FUNC_QUALIFIER vecType<T, P> prev_float(vecType<T, P> const & x) + template<length_t L, typename T, qualifier Q> + GLM_FUNC_QUALIFIER vec<L, T, Q> prev_float(vec<L, T, Q> const& x) { - vecType<T, P> Result(uninitialize); + vec<L, T, Q> Result; for(length_t i = 0, n = Result.length(); i < n; ++i) Result[i] = prev_float(x[i]); return Result; } - template <typename T> - GLM_FUNC_QUALIFIER T next_float(T const & x, uint const & ulps) + template<typename T> + GLM_FUNC_QUALIFIER T next_float(T const& x, uint const& ulps) { T temp = x; for(uint i = 0; i < ulps; ++i) @@ -252,17 +270,17 @@ namespace glm return temp; } - template<typename T, precision P, template<typename, precision> class vecType> - GLM_FUNC_QUALIFIER vecType<T, P> next_float(vecType<T, P> const & x, vecType<uint, P> const & ulps) + template<length_t L, typename T, qualifier Q> + GLM_FUNC_QUALIFIER vec<L, T, Q> next_float(vec<L, T, Q> const& x, vec<L, uint, Q> const& ulps) { - vecType<T, P> Result(uninitialize); + vec<L, T, Q> Result; for(length_t i = 0, n = Result.length(); i < n; ++i) Result[i] = next_float(x[i], ulps[i]); return Result; } - template <typename T> - GLM_FUNC_QUALIFIER T prev_float(T const & x, uint const & ulps) + template<typename T> + GLM_FUNC_QUALIFIER T prev_float(T const& x, uint const& ulps) { T temp = x; for(uint i = 0; i < ulps; ++i) @@ -270,24 +288,24 @@ namespace glm return temp; } - template<typename T, precision P, template<typename, precision> class vecType> - GLM_FUNC_QUALIFIER vecType<T, P> prev_float(vecType<T, P> const & x, vecType<uint, P> const & ulps) + template<length_t L, typename T, qualifier Q> + GLM_FUNC_QUALIFIER vec<L, T, Q> prev_float(vec<L, T, Q> const& x, vec<L, uint, Q> const& ulps) { - vecType<T, P> Result(uninitialize); + vec<L, T, Q> Result; for(length_t i = 0, n = Result.length(); i < n; ++i) Result[i] = prev_float(x[i], ulps[i]); return Result; } - template <typename T> - GLM_FUNC_QUALIFIER uint float_distance(T const & x, T const & y) + template<typename T> + GLM_FUNC_QUALIFIER uint float_distance(T const& x, T const& y) { uint ulp = 0; if(x < y) { T temp = x; - while(temp != y)// && ulp < std::numeric_limits<std::size_t>::max()) + while(glm::epsilonNotEqual(temp, y, glm::epsilon<T>()))// && ulp < std::numeric_limits<std::size_t>::max()) { ++ulp; temp = next_float(temp); @@ -296,7 +314,7 @@ namespace glm else if(y < x) { T temp = y; - while(temp != x)// && ulp < std::numeric_limits<std::size_t>::max()) + while(glm::epsilonNotEqual(temp, x, glm::epsilon<T>()))// && ulp < std::numeric_limits<std::size_t>::max()) { ++ulp; temp = next_float(temp); @@ -310,10 +328,10 @@ namespace glm return ulp; } - template<typename T, precision P, template<typename, precision> class vecType> - GLM_FUNC_QUALIFIER vecType<uint, P> float_distance(vecType<T, P> const & x, vecType<T, P> const & y) + template<length_t L, typename T, qualifier Q> + GLM_FUNC_QUALIFIER vec<L, uint, Q> float_distance(vec<L, T, Q> const& x, vec<L, T, Q> const& y) { - vecType<uint, P> Result(uninitialize); + vec<L, uint, Q> Result; for(length_t i = 0, n = Result.length(); i < n; ++i) Result[i] = float_distance(x[i], y[i]); return Result; |