Bug 100

Summary: DefaultValue::Bind() is not correct for floating points
Product: ns-3 Reporter: Tom Henderson <tomh>
Component: coreAssignee: ns-bugs <ns-bugs>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: pre-release   
Hardware: All   
OS: All   
Attachments: proposed patch that does not use numeric_limits for bounds checking
patch according to Mathieu's suggestion

Description Tom Henderson 2007-11-02 10:47:42 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?
Comment 1 Tom Henderson 2007-11-08 00:57:36 UTC
Created attachment 85 [details]
proposed patch that does not use numeric_limits for bounds checking
Comment 2 Mathieu Lacage 2007-11-08 02:36:51 UTC
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.
Comment 3 Tom Henderson 2007-11-09 01:36:23 UTC
Created attachment 87 [details]
patch according to Mathieu's suggestion

thanks for the tip
Comment 4 Tom Henderson 2007-11-14 23:57:25 UTC
fixed with changeset 1822