From 46fe7a3d9ec14ea56a879c48ba7f15e78342c8cb Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Mon, 1 Sep 2008 17:31:21 +0000 Subject: if EIGEN_NICE_RANDOM is defined, the random functions will return numbers with few bits left of the comma and for floating-point types will never return zero. This replaces the custom functions in test/main.h, so one does not anymore need to think about that when writing tests. --- Eigen/src/Core/MathFunctions.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Eigen/src/Core') diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 8aa36bd1d..a523db4c3 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -89,7 +89,14 @@ inline float ei_pow(float x, float y) { return std::pow(x, y); } template<> inline float ei_random(float a, float b) { +#ifdef EIGEN_NICE_RANDOM + int i; + do { i = ei_random(256*int(a),256*int(b)); + } while(i==0); + return i/256.f; +#else return a + (b-a) * std::rand() / RAND_MAX; +#endif } template<> inline float ei_random() { @@ -123,7 +130,14 @@ inline double ei_pow(double x, double y) { return std::pow(x, y); } template<> inline double ei_random(double a, double b) { +#ifdef EIGEN_NICE_RANDOM + int i; + do { i= ei_random(256*int(a),256*int(b)); + } while(i==0); + return i/256.; +#else return a + (b-a) * std::rand() / RAND_MAX; +#endif } template<> inline double ei_random() { -- cgit v1.2.3