diff --git a/include/mitsuba/core/constants.h b/include/mitsuba/core/constants.h index 5ca9b397..52f8a2c9 100644 --- a/include/mitsuba/core/constants.h +++ b/include/mitsuba/core/constants.h @@ -47,31 +47,31 @@ #undef INFINITY #endif +#if defined(__WINDOWS__) +#define ONE_MINUS_EPS_FLT 0.999999940395355225f +#define ONE_MINUS_EPS_DBL 0.999999999999999888 +#else +#define ONE_MINUS_EPS_FLT 0x1.fffffffffffff7p-1 +#define ONE_MINUS_EPS_DBL 0x1.fffffep-1f +#endif + #ifdef SINGLE_PRECISION -#define M_E 2.71828182845904523536f -#define M_PI 3.14159265358979323846f -#define INV_PI 0.31830988618379067154f -#define INV_TWOPI 0.15915494309189533577f -#define INV_FOURPI 0.07957747154594766788f -#define SQRT_TWO 1.41421356237309504880f -#define INV_SQRT_TWO 0.70710678118654752440f -#if defined(__WINDOWS__) -#define ONE_MINUS_EPS 0.999999940395355225f +#define M_E 2.71828182845904523536f +#define M_PI 3.14159265358979323846f +#define INV_PI 0.31830988618379067154f +#define INV_TWOPI 0.15915494309189533577f +#define INV_FOURPI 0.07957747154594766788f +#define SQRT_TWO 1.41421356237309504880f +#define INV_SQRT_TWO 0.70710678118654752440f +#define ONE_MINUS_EPS ONE_MINUS_EPS_FLT #else -#define ONE_MINUS_EPS 0x1.fffffep-1f -#endif -#else -#define M_E 2.71828182845904523536 -#define M_PI 3.14159265358979323846 -#define INV_PI 0.31830988618379067154 -#define INV_TWOPI 0.15915494309189533577 -#define INV_FOURPI 0.07957747154594766788 -#define SQRT_TWO 1.41421356237309504880 -#define INV_SQRT_TWO 0.70710678118654752440 -#if defined(__WINDOWS__) -#define ONE_MINUS_EPS 0.999999999999999888 -#else -#define ONE_MINUS_EPS 0x1.fffffffffffff7p-1 -#endif +#define M_E 2.71828182845904523536 +#define M_PI 3.14159265358979323846 +#define INV_PI 0.31830988618379067154 +#define INV_TWOPI 0.15915494309189533577 +#define INV_FOURPI 0.07957747154594766788 +#define SQRT_TWO 1.41421356237309504880 +#define INV_SQRT_TWO 0.70710678118654752440 +#define ONE_MINUS_EPS ONE_MINUS_EPS_DBL #endif #endif /* __MITSUBA_CORE_CONSTANTS_H */ diff --git a/src/samplers/sobolseq.h b/src/samplers/sobolseq.h index 383beefb..4942136a 100644 --- a/src/samplers/sobolseq.h +++ b/src/samplers/sobolseq.h @@ -54,7 +54,7 @@ inline float sampleSingle( result ^= Matrices::matrices32[i]; } - return result * (1.f / (1ULL << 32)); + return std::min(result * (1.0f / (1ULL << 32)), ONE_MINUS_EPS_FLT); } // Compute one component of the Sobol'-sequence, where the component @@ -77,7 +77,7 @@ inline double sampleDouble( result ^= Matrices::matrices64[i]; } - return result * (1.0 / (1ULL << Matrices::size)); + return std::min(result * (1.0 / (1ULL << Matrices::size)), ONE_MINUS_EPS_DBL); } // Call sampleSingle or sampleDouble depending on the compilation options