diff options
author | 2008-09-01 17:31:21 +0000 | |
---|---|---|
committer | 2008-09-01 17:31:21 +0000 | |
commit | 46fe7a3d9ec14ea56a879c48ba7f15e78342c8cb (patch) | |
tree | c708710574525c93c9732d23e7e935863434b9ac /Eigen/src/Core | |
parent | 49ff9b204c8ddd448fe214fdaf8622c4fe97c795 (diff) |
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.
Diffstat (limited to 'Eigen/src/Core')
-rw-r--r-- | Eigen/src/Core/MathFunctions.h | 14 |
1 files changed, 14 insertions, 0 deletions
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<int>(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<int>(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() { |