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.
This commit is contained in:
Benoit Jacob
2008-09-01 17:31:21 +00:00
parent 49ff9b204c
commit 46fe7a3d9e
15 changed files with 78 additions and 83 deletions

View File

@@ -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()
{