Bugzilla – Bug 100
DefaultValue::Bind() is not correct for floating points
Last modified: 2008-07-01 13:32:19 UTC
This code snippet does not work: NumericDefaultValue<double> y ("test-y", "help-y", 10.0); DefaultValue::Bind ("test-y", "0"); // fails DefaultValue::Bind ("test-y", "-1.0"); //fails DefaultValue::Bind ("test-y", "1.0"); // OK This bind will fail unless the default value passed is greater than zero. The problem is in NumericDefaultValue::DoParseValue because the value is compared against std::numeric_limits<double>::min() and max(), which are both positive numbers. One change would be to separate integer from float default values. However, I question whether the DoParseValue() code is even doing the right thing, because the act of passing the string value into a numeric value before the comparison is made is going to put this test m_value within range of the numeric limits. So perhaps the right solution is to remove these checks for NumericDefaultValue?
Created attachment 85 [details] proposed patch that does not use numeric_limits for bounds checking
I think that a more appropriate patch would be something along the lines of: template <typename T> T real_min() { if(numeric_limits<T>::is_integer) return numeric_limits<T>::min(); else return -numeric_limits<T>::max(); } which I found with google.
Created attachment 87 [details] patch according to Mathieu's suggestion thanks for the tip
fixed with changeset 1822