From 76683aa28756340ef69da631b2584e067fe9ba7e Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 26 Sep 2018 18:27:55 +0200 Subject: [PATCH] Added vector ulp functions --- glm/ext/scalar_ulp.hpp | 73 ++++++ glm/ext/scalar_ulp.inl | 282 ++++++++++++++++++++++++ glm/ext/vector_ulp.hpp | 91 ++++++++ glm/ext/vector_ulp.inl | 74 +++++++ glm/gtc/ulp.hpp | 54 +---- glm/gtc/ulp.inl | 331 ---------------------------- manual.md | 34 +++ test/core/core_func_exponential.cpp | 85 ++++--- test/ext/CMakeLists.txt | 3 + test/ext/ext_scalar_ulp.cpp | 96 ++++++++ test/ext/ext_vector_ulp.cpp | 99 +++++++++ 11 files changed, 796 insertions(+), 426 deletions(-) create mode 100644 glm/ext/scalar_ulp.hpp create mode 100644 glm/ext/scalar_ulp.inl create mode 100644 glm/ext/vector_ulp.hpp create mode 100644 glm/ext/vector_ulp.inl create mode 100644 test/ext/ext_scalar_ulp.cpp create mode 100644 test/ext/ext_vector_ulp.cpp diff --git a/glm/ext/scalar_ulp.hpp b/glm/ext/scalar_ulp.hpp new file mode 100644 index 00000000..f0db0d0a --- /dev/null +++ b/glm/ext/scalar_ulp.hpp @@ -0,0 +1,73 @@ +/// @ref ext_scalar_ulp +/// @file glm/ext/scalar_ulp.hpp +/// +/// @defgroup ext_scalar_ulp GLM_EXT_scalar_ulp +/// @ingroup ext +/// +/// Allow the measurement of the accuracy of a function against a reference +/// implementation. This extension works on floating-point data and provide results +/// in ULP. +/// +/// Include to use the features of this extension. +/// +/// @see ext_vector_ulp +/// @see ext_scalar_relational + +#pragma once + +// Dependencies +#include "../ext/scalar_int_sized.hpp" +#include "../detail/qualifier.hpp" + +#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_EXT_scalar_ulp extension included") +#endif + +namespace glm +{ + /// Return the next ULP value(s) after the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL genType next_float(genType x); + + /// Return the previous ULP value(s) before the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL genType prev_float(genType x); + + /// Return the value(s) ULP distance after the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL genType next_float(genType x, int ULPs); + + /// Return the value(s) ULP distance before the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL genType prev_float(genType x, int ULPs); + + /// Return the distance in the number of ULP between 2 single-precision floating-point scalars. + /// + /// @see ext_scalar_ulp + GLM_FUNC_DECL int float_distance(float x, float y); + + /// Return the distance in the number of ULP between 2 double-precision floating-point scalars. + /// + /// @see ext_scalar_ulp + GLM_FUNC_DECL int64 float_distance(double x, double y); + + /// @} +}//namespace glm + +#include "scalar_ulp.inl" diff --git a/glm/ext/scalar_ulp.inl b/glm/ext/scalar_ulp.inl new file mode 100644 index 00000000..11c0c017 --- /dev/null +++ b/glm/ext/scalar_ulp.inl @@ -0,0 +1,282 @@ +/// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. +/// +/// Developed at SunPro, a Sun Microsystems, Inc. business. +/// Permission to use, copy, modify, and distribute this +/// software is freely granted, provided that this notice +/// is preserved. + +#include "../detail/type_float.hpp" +#include "../ext/scalar_constants.hpp" + +#if(GLM_COMPILER & GLM_COMPILER_VC) +# pragma warning(push) +# pragma warning(disable : 4127) +#endif + +typedef union +{ + float value; + /* FIXME: Assumes 32 bit int. */ + unsigned int word; +} ieee_float_shape_type; + +typedef union +{ + double value; + struct + { + int lsw; + int msw; + } parts; +} ieee_double_shape_type; + +#define GLM_EXTRACT_WORDS(ix0,ix1,d) \ + do { \ + ieee_double_shape_type ew_u; \ + ew_u.value = (d); \ + (ix0) = ew_u.parts.msw; \ + (ix1) = ew_u.parts.lsw; \ + } while (0) + +#define GLM_GET_FLOAT_WORD(i,d) \ + do { \ + ieee_float_shape_type gf_u; \ + gf_u.value = (d); \ + (i) = gf_u.word; \ + } while (0) + +#define GLM_SET_FLOAT_WORD(d,i) \ + do { \ + ieee_float_shape_type sf_u; \ + sf_u.word = (i); \ + (d) = sf_u.value; \ + } while (0) + +#define GLM_INSERT_WORDS(d,ix0,ix1) \ + do { \ + ieee_double_shape_type iw_u; \ + iw_u.parts.msw = (ix0); \ + iw_u.parts.lsw = (ix1); \ + (d) = iw_u.value; \ + } while (0) + +namespace glm{ +namespace detail +{ + GLM_FUNC_QUALIFIER float nextafterf(float x, float y) + { + volatile float t; + int hx, hy, ix, iy; + + GLM_GET_FLOAT_WORD(hx, x); + GLM_GET_FLOAT_WORD(hy, y); + ix = hx & 0x7fffffff; // |x| + iy = hy & 0x7fffffff; // |y| + + if((ix > 0x7f800000) || // x is nan + (iy > 0x7f800000)) // y is nan + return x + y; + if(abs(y - x) <= epsilon()) + 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(abs(t - x) <= epsilon()) + return t; + else + return x; // raise underflow flag + } + if(hx >= 0) + { // x > 0 + if(hx > hy) // x > y, x -= ulp + hx -= 1; + else // x < y, x += ulp + hx += 1; + } + else + { // x < 0 + if(hy >= 0 || hx > hy) // x < y, x -= ulp + hx -= 1; + else // x > y, x += ulp + hx += 1; + } + hy = hx & 0x7f800000; + if(hy >= 0x7f800000) + return x + x; // overflow + if(hy < 0x00800000) // underflow + { + t = x * x; + if(abs(t - x) > epsilon()) + { // raise underflow flag + GLM_SET_FLOAT_WORD(y, hx); + return y; + } + } + GLM_SET_FLOAT_WORD(x, hx); + return x; + } + + GLM_FUNC_QUALIFIER double nextafter(double x, double y) + { + volatile double t; + int hx, hy, ix, iy; + unsigned int lx, ly; + + GLM_EXTRACT_WORDS(hx, lx, x); + GLM_EXTRACT_WORDS(hy, ly, 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 + return x + y; + if(abs(y - x) <= epsilon()) + 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(abs(t - x) <= epsilon()) + 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(lx == 0) hx -= 1; + lx -= 1; + } + else { // x < y, x += ulp + lx += 1; + if(lx == 0) hx += 1; + } + } + else { // x < 0 + if(hy >= 0 || 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; + } + } + hy = hx & 0x7ff00000; + if(hy >= 0x7ff00000) + return x + x; // overflow + if(hy < 0x00100000) + { // underflow + t = x * x; + if(abs(t - x) > epsilon()) + { // raise underflow flag + GLM_INSERT_WORDS(y, hx, lx); + return y; + } + } + GLM_INSERT_WORDS(x, hx, lx); + return x; + } +}//namespace detail +}//namespace glm + +#if(GLM_COMPILER & GLM_COMPILER_VC) +# pragma warning(pop) +#endif + +namespace glm +{ + template<> + GLM_FUNC_QUALIFIER float next_float(float x) + { +# if GLM_HAS_CXX11_STL + return std::nextafter(x, std::numeric_limits::max()); +# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) + return detail::nextafterf(x, FLT_MAX); +# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) + return __builtin_nextafterf(x, FLT_MAX); +# else + return nextafterf(x, FLT_MAX); +# endif + } + + template<> + GLM_FUNC_QUALIFIER double next_float(double x) + { +# if GLM_HAS_CXX11_STL + return std::nextafter(x, std::numeric_limits::max()); +# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) + return detail::nextafter(x, std::numeric_limits::max()); +# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) + return __builtin_nextafter(x, FLT_MAX); +# else + return nextafter(x, DBL_MAX); +# endif + } + + template + GLM_FUNC_QUALIFIER T next_float(T x, int ULPs) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'next_float' only accept floating-point input"); + assert(ULPs >= 0); + + T temp = x; + for(int i = 0; i < ULPs; ++i) + temp = next_float(temp); + return temp; + } + + GLM_FUNC_QUALIFIER float prev_float(float x) + { +# if GLM_HAS_CXX11_STL + return std::nextafter(x, std::numeric_limits::min()); +# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) + return detail::nextafterf(x, FLT_MIN); +# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) + return __builtin_nextafterf(x, FLT_MIN); +# else + return nextafterf(x, FLT_MIN); +# endif + } + + GLM_FUNC_QUALIFIER double prev_float(double x) + { +# if GLM_HAS_CXX11_STL + return std::nextafter(x, std::numeric_limits::min()); +# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) + return _nextafter(x, DBL_MIN); +# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) + return __builtin_nextafter(x, DBL_MIN); +# else + return nextafter(x, DBL_MIN); +# endif + } + + template + GLM_FUNC_QUALIFIER T prev_float(T x, int ULPs) + { + GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'prev_float' only accept floating-point input"); + assert(ULPs >= 0); + + T temp = x; + for(int i = 0; i < ULPs; ++i) + temp = prev_float(temp); + return temp; + } + + GLM_FUNC_QUALIFIER int float_distance(float x, float y) + { + detail::float_t const a(x); + detail::float_t const b(y); + + return abs(a.i - b.i); + } + + GLM_FUNC_QUALIFIER int64 float_distance(double x, double y) + { + detail::float_t const a(x); + detail::float_t const b(y); + + return abs(a.i - b.i); + } +}//namespace glm diff --git a/glm/ext/vector_ulp.hpp b/glm/ext/vector_ulp.hpp new file mode 100644 index 00000000..bc5d6b82 --- /dev/null +++ b/glm/ext/vector_ulp.hpp @@ -0,0 +1,91 @@ +/// @ref ext_vector_ulp +/// @file glm/ext/vector_ulp.hpp +/// +/// @defgroup ext_vector_ulp GLM_EXT_vector_ulp +/// @ingroup ext +/// +/// Allow the measurement of the accuracy of a function against a reference +/// implementation. This extension works on floating-point data and provide results +/// in ULP. +/// +/// Include to use the features of this extension. +/// +/// @see ext_scalar_ulp +/// @see ext_scalar_relational +/// @see ext_vector_relational + +#pragma once + +// Dependencies +#include "../ext/scalar_ulp.hpp" + +#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) +# pragma message("GLM: GLM_EXT_vector_ulp extension included") +#endif + +namespace glm +{ + /// Return the next ULP value(s) after the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL vec next_float(vec const& x); + + /// Return the value(s) ULP distance after the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL vec next_float(vec const& x, int ULPs); + + /// Return the value(s) ULP distance after the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL vec next_float(vec const& x, vec const& ULPs); + + /// Return the previous ULP value(s) before the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL vec prev_float(vec const& x); + + /// Return the value(s) ULP distance before the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL vec prev_float(vec const& x, int ULPs); + + /// Return the value(s) ULP distance before the input value(s). + /// + /// @tparam genType A floating-point scalar type. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL vec prev_float(vec const& x, vec const& ULPs); + + /// Return the distance in the number of ULP between 2 single-precision floating-point scalars. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL vec float_distance(vec const& x, vec const& y); + + /// Return the distance in the number of ULP between 2 double-precision floating-point scalars. + /// + /// @see ext_scalar_ulp + template + GLM_FUNC_DECL vec float_distance(vec const& x, vec const& y); + + /// @} +}//namespace glm + +#include "vector_ulp.inl" diff --git a/glm/ext/vector_ulp.inl b/glm/ext/vector_ulp.inl new file mode 100644 index 00000000..86465343 --- /dev/null +++ b/glm/ext/vector_ulp.inl @@ -0,0 +1,74 @@ +namespace glm +{ + template + GLM_FUNC_QUALIFIER vec next_float(vec const& x) + { + vec Result; + for(length_t i = 0, n = Result.length(); i < n; ++i) + Result[i] = next_float(x[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec next_float(vec const& x, int ULPs) + { + vec Result; + for(length_t i = 0, n = Result.length(); i < n; ++i) + Result[i] = next_float(x[i], ULPs); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec next_float(vec const& x, vec const& ULPs) + { + vec Result; + for(length_t i = 0, n = Result.length(); i < n; ++i) + Result[i] = next_float(x[i], ULPs[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec prev_float(vec const& x) + { + vec Result; + for(length_t i = 0, n = Result.length(); i < n; ++i) + Result[i] = prev_float(x[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec prev_float(vec const& x, int ULPs) + { + vec Result; + for(length_t i = 0, n = Result.length(); i < n; ++i) + Result[i] = prev_float(x[i], ULPs); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec prev_float(vec const& x, vec const& ULPs) + { + vec Result; + for(length_t i = 0, n = Result.length(); i < n; ++i) + Result[i] = prev_float(x[i], ULPs[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec float_distance(vec const& x, vec const& y) + { + vec Result; + for(length_t i = 0, n = Result.length(); i < n; ++i) + Result[i] = float_distance(x[i], y[i]); + return Result; + } + + template + GLM_FUNC_QUALIFIER vec float_distance(vec const& x, vec const& y) + { + vec Result; + for(length_t i = 0, n = Result.length(); i < n; ++i) + Result[i] = float_distance(x[i], y[i]); + return Result; + } +}//namespace glm diff --git a/glm/gtc/ulp.hpp b/glm/gtc/ulp.hpp index 11665a2c..01f4f11e 100644 --- a/glm/gtc/ulp.hpp +++ b/glm/gtc/ulp.hpp @@ -15,60 +15,10 @@ #pragma once // Dependencies -#include "../gtc/constants.hpp" -#include "../ext/vector_relational.hpp" -#include "../ext/scalar_int_sized.hpp" +#include "../ext/scalar_ulp.hpp" +#include "../ext/vector_ulp.hpp" #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) # pragma message("GLM: GLM_GTC_ulp extension included") #endif -namespace glm -{ - /// @addtogroup gtc_ulp - /// @{ - - /// Return the next ULP value(s) after the input value(s). - /// @see gtc_ulp - template - GLM_FUNC_DECL genType next_float(genType const& x); - - /// Return the previous ULP value(s) before the input value(s). - /// @see gtc_ulp - template - GLM_FUNC_DECL genType prev_float(genType const& x); - - /// Return the value(s) ULP distance after the input value(s). - /// @see gtc_ulp - template - GLM_FUNC_DECL genType next_float(genType const& x, int DistanceULPs); - - /// Return the value(s) ULP distance before the input value(s). - /// @see gtc_ulp - template - GLM_FUNC_DECL genType prev_float(genType const& x, int DistanceULPs); - - /// Return the distance in the number of ULP between 2 single-precision floating-point scalars. - /// @see gtc_ulp - template - GLM_FUNC_DECL int float_distance(float x, float y); - - /// Return the distance in the number of ULP between 2 double-precision floating-point scalars. - /// @see gtc_ulp - template - GLM_FUNC_DECL int64 float_distance(double x, double y); - - /// Return the distance in the number of ULP between single-precision floating-point 2 vectors. - /// @see gtc_ulp - template - GLM_FUNC_DECL vec float_distance(vec const& x, vec const& y); - - /// Return the distance in the number of ULP between double-precision floating-point 2 vectors. - /// @see gtc_ulp - template - GLM_FUNC_DECL vec float_distance(vec const& x, vec const& y); - - /// @} -}// namespace glm - -#include "ulp.inl" diff --git a/glm/gtc/ulp.inl b/glm/gtc/ulp.inl index 2251407e..53f4950a 100644 --- a/glm/gtc/ulp.inl +++ b/glm/gtc/ulp.inl @@ -1,334 +1,3 @@ /// @ref gtc_ulp /// -/// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. -/// -/// Developed at SunPro, a Sun Microsystems, Inc. business. -/// Permission to use, copy, modify, and distribute this -/// software is freely granted, provided that this notice -/// is preserved. -#include "epsilon.hpp" -#include -#include -#include -#include "../detail/type_float.hpp" - -#if(GLM_COMPILER & GLM_COMPILER_VC) -# pragma warning(push) -# pragma warning(disable : 4127) -#endif - -typedef union -{ - float value; - /* FIXME: Assumes 32 bit int. */ - unsigned int word; -} ieee_float_shape_type; - -typedef union -{ - double value; - struct - { - int lsw; - int msw; - } parts; -} ieee_double_shape_type; - -#define GLM_EXTRACT_WORDS(ix0,ix1,d) \ - do { \ - ieee_double_shape_type ew_u; \ - ew_u.value = (d); \ - (ix0) = ew_u.parts.msw; \ - (ix1) = ew_u.parts.lsw; \ - } while (0) - -#define GLM_GET_FLOAT_WORD(i,d) \ - do { \ - ieee_float_shape_type gf_u; \ - gf_u.value = (d); \ - (i) = gf_u.word; \ - } while (0) - -#define GLM_SET_FLOAT_WORD(d,i) \ - do { \ - ieee_float_shape_type sf_u; \ - sf_u.word = (i); \ - (d) = sf_u.value; \ - } while (0) - -#define GLM_INSERT_WORDS(d,ix0,ix1) \ - do { \ - ieee_double_shape_type iw_u; \ - iw_u.parts.msw = (ix0); \ - iw_u.parts.lsw = (ix1); \ - (d) = iw_u.value; \ - } while (0) - -namespace glm{ -namespace detail -{ - GLM_FUNC_QUALIFIER float nextafterf(float x, float y) - { - volatile float t; - int hx, hy, ix, iy; - - GLM_GET_FLOAT_WORD(hx, x); - GLM_GET_FLOAT_WORD(hy, y); - ix = hx&0x7fffffff; // |x| - iy = hy&0x7fffffff; // |y| - - if((ix>0x7f800000) || // x is nan - (iy>0x7f800000)) // y is nan - return x+y; - if(abs(y - x) <= epsilon()) - 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(abs(t - x) <= epsilon()) - return t; - else - return x; // raise underflow flag - } - if(hx>=0) - { // x > 0 - if(hx>hy) // x > y, x -= ulp - hx -= 1; - else // x < y, x += ulp - hx += 1; - } - else - { // x < 0 - if(hy>=0||hx>hy) // x < y, x -= ulp - hx -= 1; - else // x > y, x += ulp - hx += 1; - } - hy = hx&0x7f800000; - if(hy>=0x7f800000) - return x+x; // overflow - if(hy<0x00800000) // underflow - { - t = x*x; - if(abs(t - x) > epsilon()) - { // raise underflow flag - GLM_SET_FLOAT_WORD(y,hx); - return y; - } - } - GLM_SET_FLOAT_WORD(x,hx); - return x; - } - - GLM_FUNC_QUALIFIER double nextafter(double x, double y) - { - volatile double t; - int hx, hy, ix, iy; - unsigned int lx, ly; - - GLM_EXTRACT_WORDS(hx, lx, x); - GLM_EXTRACT_WORDS(hy, ly, 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 - return x+y; - if(abs(y - x) <= epsilon()) - 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(abs(t - x) <= epsilon()) - 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(lx==0) hx -= 1; - lx -= 1; - } else { // x < y, x += ulp - lx += 1; - if(lx==0) hx += 1; - } - } else { // x < 0 - if(hy>=0||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; - } - } - hy = hx&0x7ff00000; - if(hy>=0x7ff00000) - return x+x; // overflow - if(hy<0x00100000) - { // underflow - t = x*x; - if(abs(t - x) > epsilon()) - { // raise underflow flag - GLM_INSERT_WORDS(y,hx,lx); - return y; - } - } - GLM_INSERT_WORDS(x,hx,lx); - return x; - } -}//namespace detail -}//namespace glm - -#if(GLM_COMPILER & GLM_COMPILER_VC) -# pragma warning(pop) -#endif - -namespace glm -{ - template<> - GLM_FUNC_QUALIFIER float next_float(float const& x) - { -# if GLM_HAS_CXX11_STL - return std::nextafter(x, std::numeric_limits::max()); -# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) - return detail::nextafterf(x, FLT_MAX); -# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) - return __builtin_nextafterf(x, FLT_MAX); -# else - return nextafterf(x, FLT_MAX); -# endif - } - - template<> - GLM_FUNC_QUALIFIER double next_float(double const& x) - { -# if GLM_HAS_CXX11_STL - return std::nextafter(x, std::numeric_limits::max()); -# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) - return detail::nextafter(x, std::numeric_limits::max()); -# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) - return __builtin_nextafter(x, FLT_MAX); -# else - return nextafter(x, DBL_MAX); -# endif - } - - template - GLM_FUNC_QUALIFIER vec next_float(vec const& x) - { - vec 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) - { -# if GLM_HAS_CXX11_STL - return std::nextafter(x, std::numeric_limits::min()); -# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) - return detail::nextafterf(x, FLT_MIN); -# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) - return __builtin_nextafterf(x, FLT_MIN); -# else - return nextafterf(x, FLT_MIN); -# endif - } - - GLM_FUNC_QUALIFIER double prev_float(double const& x) - { -# if GLM_HAS_CXX11_STL - return std::nextafter(x, std::numeric_limits::min()); -# elif((GLM_COMPILER & GLM_COMPILER_VC) || ((GLM_COMPILER & GLM_COMPILER_INTEL) && (GLM_PLATFORM & GLM_PLATFORM_WINDOWS))) - return _nextafter(x, DBL_MIN); -# elif(GLM_PLATFORM & GLM_PLATFORM_ANDROID) - return __builtin_nextafter(x, DBL_MIN); -# else - return nextafter(x, DBL_MIN); -# endif - } - - template - GLM_FUNC_QUALIFIER vec prev_float(vec const& x) - { - vec Result; - for(length_t i = 0, n = Result.length(); i < n; ++i) - Result[i] = prev_float(x[i]); - return Result; - } - - template - GLM_FUNC_QUALIFIER T next_float(T const& x, int ulps) - { - T temp = x; - for(int i = 0; i < ulps; ++i) - temp = next_float(temp); - return temp; - } - - template - GLM_FUNC_QUALIFIER vec next_float(vec const& x, vec const& ulps) - { - vec Result; - for(length_t i = 0, n = Result.length(); i < n; ++i) - Result[i] = next_float(x[i], ulps[i]); - return Result; - } - - template - GLM_FUNC_QUALIFIER T prev_float(T const& x, int ulps) - { - assert(ulps >= 0); - - T temp = x; - for(int i = 0; i < ulps; ++i) - temp = prev_float(temp); - return temp; - } - - template - GLM_FUNC_QUALIFIER vec prev_float(vec const& x, vec const& ulps) - { - vec Result; - for(length_t i = 0, n = Result.length(); i < n; ++i) - Result[i] = prev_float(x[i], ulps[i]); - return Result; - } - - GLM_FUNC_QUALIFIER int float_distance(float x, float y) - { - detail::float_t const a(x); - detail::float_t const b(y); - - return abs(a.i - b.i); - } - - GLM_FUNC_QUALIFIER int64 float_distance(double x, double y) - { - detail::float_t const a(x); - detail::float_t const b(y); - - return abs(a.i - b.i); - } - - template - GLM_FUNC_QUALIFIER vec float_distance(vec const& x, vec const& y) - { - vec Result; - for(length_t i = 0, n = Result.length(); i < n; ++i) - Result[i] = float_distance(x[i], y[i]); - return Result; - } - - template - GLM_FUNC_QUALIFIER vec float_distance(vec const& x, vec const& y) - { - vec Result; - for(length_t i = 0, n = Result.length(); i < n; ++i) - Result[i] = float_distance(x[i], y[i]); - return Result; - } -}//namespace glm diff --git a/manual.md b/manual.md index e4b34f16..eed6c04f 100644 --- a/manual.md +++ b/manual.md @@ -792,6 +792,22 @@ bool equalULP1(float const a, float const b) Include `` to use these features. +#### 3.2.4. GLM_EXT_scalar_ulp + +This extension exposes function that measure of accuracy in numeric calculations. + +```cpp +#include + +bool test_ulp(float x) +{ + float const a = glm::next_float(x); // return a float a ULP away from the float argument. + return float_distance(a, x) == 1; // check both float are a single ULP away. +} +``` + +Include `` to use these features. + ### 3.3. Vector types #### 3.3.1. GLM_EXT_vector_float1 @@ -999,6 +1015,24 @@ bool epsilonEqual(glm::vec2 const& A, glm::vec2 const& B) Include `` to use these features. +#### 3.5.3. GLM_EXT_vector_ulp + +This extension exposes function that measure of accuracy in numeric calculations. + +```cpp +#include +#include +#include + +bool test_ulp(glm::vec4 const& x) +{ + glm::vec4 const a = glm::next_float(x); // return a float a ULP away from the float argument. + return glm::all(float_distance(a, x) == glm::ivec4(1)); // check both float are a single ULP away. +} +``` + +Include `` to use these features. + ### 3.6. Matrix types #### 3.6.1. GLM_EXT_matrix_float2x2 diff --git a/test/core/core_func_exponential.cpp b/test/core/core_func_exponential.cpp index ac49ac08..a414a4e9 100644 --- a/test/core/core_func_exponential.cpp +++ b/test/core/core_func_exponential.cpp @@ -1,31 +1,31 @@ -#include -#include #include -#include +#include #include #include #include #include #include +#include +#include static int test_pow() { int Error(0); float A = glm::pow(2.f, 2.f); - Error += glm::epsilonEqual(A, 4.f, 0.01f) ? 0 : 1; + Error += glm::equal(A, 4.f, 0.01f) ? 0 : 1; glm::vec1 B = glm::pow(glm::vec1(2.f), glm::vec1(2.f)); - Error += glm::all(glm::epsilonEqual(B, glm::vec1(4.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(B, glm::vec1(4.f), 0.01f)) ? 0 : 1; glm::vec2 C = glm::pow(glm::vec2(2.f), glm::vec2(2.f)); - Error += glm::all(glm::epsilonEqual(C, glm::vec2(4.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(C, glm::vec2(4.f), 0.01f)) ? 0 : 1; glm::vec3 D = glm::pow(glm::vec3(2.f), glm::vec3(2.f)); - Error += glm::all(glm::epsilonEqual(D, glm::vec3(4.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(D, glm::vec3(4.f), 0.01f)) ? 0 : 1; glm::vec4 E = glm::pow(glm::vec4(2.f), glm::vec4(2.f)); - Error += glm::all(glm::epsilonEqual(E, glm::vec4(4.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(E, glm::vec4(4.f), 0.01f)) ? 0 : 1; return Error; } @@ -35,42 +35,41 @@ static int test_sqrt() int Error = 0; float A = glm::sqrt(4.f); - Error += glm::epsilonEqual(A, 2.f, 0.01f) ? 0 : 1; + Error += glm::equal(A, 2.f, 0.01f) ? 0 : 1; glm::vec1 B = glm::sqrt(glm::vec1(4.f)); - Error += glm::all(glm::epsilonEqual(B, glm::vec1(2.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(B, glm::vec1(2.f), 0.01f)) ? 0 : 1; glm::vec2 C = glm::sqrt(glm::vec2(4.f)); - Error += glm::all(glm::epsilonEqual(C, glm::vec2(2.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(C, glm::vec2(2.f), 0.01f)) ? 0 : 1; glm::vec3 D = glm::sqrt(glm::vec3(4.f)); - Error += glm::all(glm::epsilonEqual(D, glm::vec3(2.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(D, glm::vec3(2.f), 0.01f)) ? 0 : 1; glm::vec4 E = glm::sqrt(glm::vec4(4.f)); - Error += glm::all(glm::epsilonEqual(E, glm::vec4(2.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(E, glm::vec4(2.f), 0.01f)) ? 0 : 1; return Error; } - static int test_exp() { int Error = 0; float A = glm::exp(1.f); - Error += glm::epsilonEqual(A, glm::e(), 0.01f) ? 0 : 1; + Error += glm::equal(A, glm::e(), 0.01f) ? 0 : 1; glm::vec1 B = glm::exp(glm::vec1(1.f)); - Error += glm::all(glm::epsilonEqual(B, glm::vec1(glm::e()), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(B, glm::vec1(glm::e()), 0.01f)) ? 0 : 1; glm::vec2 C = glm::exp(glm::vec2(1.f)); - Error += glm::all(glm::epsilonEqual(C, glm::vec2(glm::e()), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(C, glm::vec2(glm::e()), 0.01f)) ? 0 : 1; glm::vec3 D = glm::exp(glm::vec3(1.f)); - Error += glm::all(glm::epsilonEqual(D, glm::vec3(glm::e()), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(D, glm::vec3(glm::e()), 0.01f)) ? 0 : 1; glm::vec4 E = glm::exp(glm::vec4(1.f)); - Error += glm::all(glm::epsilonEqual(E, glm::vec4(glm::e()), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(E, glm::vec4(glm::e()), 0.01f)) ? 0 : 1; return Error; } @@ -80,19 +79,19 @@ static int test_log() int Error = 0; float const A = glm::log(glm::e()); - Error += glm::epsilonEqual(A, 1.f, 0.01f) ? 0 : 1; + Error += glm::equal(A, 1.f, 0.01f) ? 0 : 1; glm::vec1 const B = glm::log(glm::vec1(glm::e())); - Error += glm::all(glm::epsilonEqual(B, glm::vec1(1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(B, glm::vec1(1.f), 0.01f)) ? 0 : 1; glm::vec2 const C = glm::log(glm::vec2(glm::e())); - Error += glm::all(glm::epsilonEqual(C, glm::vec2(1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(C, glm::vec2(1.f), 0.01f)) ? 0 : 1; glm::vec3 const D = glm::log(glm::vec3(glm::e())); - Error += glm::all(glm::epsilonEqual(D, glm::vec3(1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(D, glm::vec3(1.f), 0.01f)) ? 0 : 1; glm::vec4 const E = glm::log(glm::vec4(glm::e())); - Error += glm::all(glm::epsilonEqual(E, glm::vec4(1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(E, glm::vec4(1.f), 0.01f)) ? 0 : 1; return Error; } @@ -102,26 +101,26 @@ static int test_exp2() int Error = 0; float A = glm::exp2(4.f); - Error += glm::epsilonEqual(A, 16.f, 0.01f) ? 0 : 1; + Error += glm::equal(A, 16.f, 0.01f) ? 0 : 1; glm::vec1 B = glm::exp2(glm::vec1(4.f)); - Error += glm::all(glm::epsilonEqual(B, glm::vec1(16.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(B, glm::vec1(16.f), 0.01f)) ? 0 : 1; glm::vec2 C = glm::exp2(glm::vec2(4.f, 3.f)); - Error += glm::all(glm::epsilonEqual(C, glm::vec2(16.f, 8.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(C, glm::vec2(16.f, 8.f), 0.01f)) ? 0 : 1; glm::vec3 D = glm::exp2(glm::vec3(4.f, 3.f, 2.f)); - Error += glm::all(glm::epsilonEqual(D, glm::vec3(16.f, 8.f, 4.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(D, glm::vec3(16.f, 8.f, 4.f), 0.01f)) ? 0 : 1; glm::vec4 E = glm::exp2(glm::vec4(4.f, 3.f, 2.f, 1.f)); - Error += glm::all(glm::epsilonEqual(E, glm::vec4(16.f, 8.f, 4.f, 2.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(E, glm::vec4(16.f, 8.f, 4.f, 2.f), 0.01f)) ? 0 : 1; # if GLM_HAS_CXX11_STL - //large exponent - float F = glm::exp2(23.f); - Error += glm::epsilonEqual(F, 8388608.f, 0.01f) ? 0 : 1; + //large exponent + float F = glm::exp2(23.f); + Error += glm::equal(F, 8388608.f, 0.01f) ? 0 : 1; # endif - + return Error; } @@ -130,19 +129,19 @@ static int test_log2() int Error = 0; float A = glm::log2(16.f); - Error += glm::epsilonEqual(A, 4.f, 0.01f) ? 0 : 1; + Error += glm::equal(A, 4.f, 0.01f) ? 0 : 1; glm::vec1 B = glm::log2(glm::vec1(16.f)); - Error += glm::all(glm::epsilonEqual(B, glm::vec1(4.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(B, glm::vec1(4.f), 0.01f)) ? 0 : 1; glm::vec2 C = glm::log2(glm::vec2(16.f, 8.f)); - Error += glm::all(glm::epsilonEqual(C, glm::vec2(4.f, 3.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(C, glm::vec2(4.f, 3.f), 0.01f)) ? 0 : 1; glm::vec3 D = glm::log2(glm::vec3(16.f, 8.f, 4.f)); - Error += glm::all(glm::epsilonEqual(D, glm::vec3(4.f, 3.f, 2.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(D, glm::vec3(4.f, 3.f, 2.f), 0.01f)) ? 0 : 1; glm::vec4 E = glm::log2(glm::vec4(16.f, 8.f, 4.f, 2.f)); - Error += glm::all(glm::epsilonEqual(E, glm::vec4(4.f, 3.f, 2.f, 1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(E, glm::vec4(4.f, 3.f, 2.f, 1.f), 0.01f)) ? 0 : 1; return Error; } @@ -152,19 +151,19 @@ static int test_inversesqrt() int Error = 0; float A = glm::inversesqrt(16.f) * glm::sqrt(16.f); - Error += glm::epsilonEqual(A, 1.f, 0.01f) ? 0 : 1; + Error += glm::equal(A, 1.f, 0.01f) ? 0 : 1; glm::vec1 B = glm::inversesqrt(glm::vec1(16.f)) * glm::sqrt(16.f);; - Error += glm::all(glm::epsilonEqual(B, glm::vec1(1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(B, glm::vec1(1.f), 0.01f)) ? 0 : 1; glm::vec2 C = glm::inversesqrt(glm::vec2(16.f)) * glm::sqrt(16.f);; - Error += glm::all(glm::epsilonEqual(C, glm::vec2(1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(C, glm::vec2(1.f), 0.01f)) ? 0 : 1; glm::vec3 D = glm::inversesqrt(glm::vec3(16.f)) * glm::sqrt(16.f);; - Error += glm::all(glm::epsilonEqual(D, glm::vec3(1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(D, glm::vec3(1.f), 0.01f)) ? 0 : 1; glm::vec4 E = glm::inversesqrt(glm::vec4(16.f)) * glm::sqrt(16.f); - Error += glm::all(glm::epsilonEqual(E, glm::vec4(1.f), 0.01f)) ? 0 : 1; + Error += glm::all(glm::equal(E, glm::vec4(1.f), 0.01f)) ? 0 : 1; return Error; } diff --git a/test/ext/CMakeLists.txt b/test/ext/CMakeLists.txt index c25cd34e..f4152e70 100644 --- a/test/ext/CMakeLists.txt +++ b/test/ext/CMakeLists.txt @@ -11,6 +11,7 @@ glmCreateTestGTC(ext_scalar_common) glmCreateTestGTC(ext_scalar_constants) glmCreateTestGTC(ext_scalar_int_sized) glmCreateTestGTC(ext_scalar_uint_sized) +glmCreateTestGTC(ext_scalar_ulp) glmCreateTestGTC(ext_scalar_relational) glmCreateTestGTC(ext_vec1) glmCreateTestGTC(ext_vector_bool1) @@ -18,3 +19,5 @@ glmCreateTestGTC(ext_vector_common) glmCreateTestGTC(ext_vector_iec559) glmCreateTestGTC(ext_vector_integer) glmCreateTestGTC(ext_vector_relational) +glmCreateTestGTC(ext_vector_ulp) + diff --git a/test/ext/ext_scalar_ulp.cpp b/test/ext/ext_scalar_ulp.cpp new file mode 100644 index 00000000..348c10ec --- /dev/null +++ b/test/ext/ext_scalar_ulp.cpp @@ -0,0 +1,96 @@ +#include +#include + +static int test_ulp_float_dist() +{ + int Error = 0; + + float A = 1.0f; + + float B = glm::next_float(A); + Error += glm::notEqual(A, B, 0) ? 0 : 1; + float C = glm::prev_float(B); + Error += glm::equal(A, C, 0) ? 0 : 1; + + int D = glm::float_distance(A, B); + Error += D == 1 ? 0 : 1; + int E = glm::float_distance(A, C); + Error += E == 0 ? 0 : 1; + + return Error; +} + +static int test_ulp_float_step() +{ + int Error = 0; + + float A = 1.0f; + + for(int i = 10; i < 1000; i *= 10) + { + float B = glm::next_float(A, i); + Error += glm::notEqual(A, B, 0) ? 0 : 1; + float C = glm::prev_float(B, i); + Error += glm::equal(A, C, 0) ? 0 : 1; + + int D = glm::float_distance(A, B); + Error += D == i ? 0 : 1; + int E = glm::float_distance(A, C); + Error += E == 0 ? 0 : 1; + } + + return Error; +} + +static int test_ulp_double_dist() +{ + int Error = 0; + + double A = 1.0; + + double B = glm::next_float(A); + Error += glm::notEqual(A, B, 0) ? 0 : 1; + double C = glm::prev_float(B); + Error += glm::equal(A, C, 0) ? 0 : 1; + + glm::int64 const D = glm::float_distance(A, B); + Error += D == 1 ? 0 : 1; + glm::int64 const E = glm::float_distance(A, C); + Error += E == 0 ? 0 : 1; + + return Error; +} + +static int test_ulp_double_step() +{ + int Error = 0; + + double A = 1.0; + + for(int i = 10; i < 1000; i *= 10) + { + double B = glm::next_float(A, i); + Error += glm::notEqual(A, B, 0) ? 0 : 1; + double C = glm::prev_float(B, i); + Error += glm::equal(A, C, 0) ? 0 : 1; + + glm::int64 const D = glm::float_distance(A, B); + Error += D == i ? 0 : 1; + glm::int64 const E = glm::float_distance(A, C); + Error += E == 0 ? 0 : 1; + } + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_ulp_float_dist(); + Error += test_ulp_float_step(); + Error += test_ulp_double_dist(); + Error += test_ulp_double_step(); + + return Error; +} diff --git a/test/ext/ext_vector_ulp.cpp b/test/ext/ext_vector_ulp.cpp new file mode 100644 index 00000000..2e7bd2fb --- /dev/null +++ b/test/ext/ext_vector_ulp.cpp @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include + +static int test_ulp_float_dist() +{ + int Error = 0; + + glm::vec4 const A(1.0f); + + glm::vec4 const B = glm::next_float(A); + Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1; + glm::vec4 const C = glm::prev_float(B); + Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1; + + glm::ivec4 const D = glm::float_distance(A, B); + Error += D == glm::ivec4(1) ? 0 : 1; + glm::ivec4 const E = glm::float_distance(A, C); + Error += E == glm::ivec4(0) ? 0 : 1; + + return Error; +} + +static int test_ulp_float_step() +{ + int Error = 0; + + glm::vec4 const A(1.0f); + + for(int i = 10; i < 1000; i *= 10) + { + glm::vec4 const B = glm::next_float(A, i); + Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1; + glm::vec4 const C = glm::prev_float(B, i); + Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1; + + glm::ivec4 const D = glm::float_distance(A, B); + Error += D == glm::ivec4(i) ? 0 : 1; + glm::ivec4 const E = glm::float_distance(A, C); + Error += E == glm::ivec4(0) ? 0 : 1; + } + + return Error; +} + +static int test_ulp_double_dist() +{ + int Error = 0; + + glm::dvec4 const A(1.0); + + glm::dvec4 const B = glm::next_float(A); + Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1; + glm::dvec4 const C = glm::prev_float(B); + Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1; + + glm::ivec4 const D(glm::float_distance(A, B)); + Error += D == glm::ivec4(1) ? 0 : 1; + glm::ivec4 const E = glm::float_distance(A, C); + Error += E == glm::ivec4(0) ? 0 : 1; + + return Error; +} + +static int test_ulp_double_step() +{ + int Error = 0; + + glm::dvec4 const A(1.0); + + for(int i = 10; i < 1000; i *= 10) + { + glm::dvec4 const B = glm::next_float(A, i); + Error += glm::any(glm::notEqual(A, B, 0)) ? 0 : 1; + glm::dvec4 const C = glm::prev_float(B, i); + Error += glm::all(glm::equal(A, C, 0)) ? 0 : 1; + + glm::ivec4 const D(glm::float_distance(A, B)); + Error += D == glm::ivec4(i) ? 0 : 1; + glm::ivec4 const E(glm::float_distance(A, C)); + Error += E == glm::ivec4(0) ? 0 : 1; + } + + return Error; +} + +int main() +{ + int Error = 0; + + Error += test_ulp_float_dist(); + Error += test_ulp_float_step(); + Error += test_ulp_double_dist(); + Error += test_ulp_double_step(); + + return Error; +}