From ce99bb02f1f6624d650ff103349f64ffed279c53 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Tue, 17 Aug 2010 14:56:33 +0200 Subject: [PATCH] use eo::log ; warning when returns 0 --- eo/src/utils/eoHowMany.h | 52 ++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/eo/src/utils/eoHowMany.h b/eo/src/utils/eoHowMany.h index 39faa8b9..a31291a0 100644 --- a/eo/src/utils/eoHowMany.h +++ b/eo/src/utils/eoHowMany.h @@ -4,6 +4,8 @@ // eoHowMany_h.h // Base class for choosing a number of guys to apply something from a popsize // (c) Marc Schoenauer, 2000 +// (c) Thales group, 2010 (Johann Dréo ) + /* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -66,6 +68,8 @@ #include +#include + class eoHowMany : public eoPersistent { public: @@ -78,19 +82,19 @@ public: { if (_interpret_as_rate) { - if (_rate<0) - { - rate = 1.0+_rate; - if (rate < 0) // was < -1 - throw std::logic_error("rate<-1 in eoHowMany!"); - } + if (_rate<0) + { + rate = 1.0+_rate; + if (rate < 0) // was < -1 + throw std::logic_error("rate<-1 in eoHowMany!"); + } } else { - rate = 0.0; // just in case, but shoud be unused - combien = int(_rate); // negative values are allowed here - if (combien != _rate) - std::cerr << "Warning: Number was rounded in eoHowMany"; + rate = 0.0; // just in case, but shoud be unused + combien = int(_rate); // negative values are allowed here + if (combien != _rate) + eo::log << eo::warnings << "Number was rounded in eoHowMany"; } } @@ -115,14 +119,20 @@ public: { if (combien == 0) { - return (unsigned int) (rate * _size); + unsigned int res = static_cast( std::ceil( rate * _size ) ); + + if( res == 0 ) { + eo::log << eo::warnings << "Call to a eoHowMany instance returns 0 (rate=" << rate << ", size=" << _size << ")" << std::endl; + } + + return res; } if (combien < 0) { - unsigned int combloc = -combien; - if (_size