|
Bugzilla – Full Text Bug Listing |
| Summary: | DefaultValue::Bind() is not correct for floating points | ||
|---|---|---|---|
| Product: | ns-3 | Reporter: | Tom Henderson <tomh> |
| Component: | core | Assignee: | 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 |
||
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 |
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?