Bug #517
MaxSquarableInteger gives wrong ans for unsigned long
Description
MaxSquarableInteger gives wrong ans for unsigned long
because conversion to double
rounds up!
Fix it!
History
#1 Updated by John Abbott almost 10 years ago
- Status changed from New to In Progress
- Priority changed from Normal to High
- % Done changed from 0 to 10
Here is a failing case:
unsigned long j = NumericLimits<unsigned long>::MaxSquarableInteger(); cout << "j=" << j << endl; cout << "j^2=" << j*j << endl;
It prints out that
j^2=0
so overflow has occurred!
Note This should be added to a test somewhere!
#2 Updated by John Abbott almost 10 years ago
- Status changed from In Progress to Feedback
- % Done changed from 10 to 90
Completely reimplemented: decided to follow design pattern used by std::numeric_limits
. Will need updating if other bit sizes are needed; currently offers only 7,8,15,16,31,32,63,64.
Added new test file test-utils2.C
#3 Updated by John Abbott almost 10 years ago
I have replaced yesterday's impl with a new much simpler and more compact one (but it is a bit slower, and relies on GMP to get the right answer).
So simple that there are obviously no deficiencies... :-)
I also changed the name to MaxSquarableInteger<T>()
; the NumericLimits
prefix was just a waste of space... of course, it would be nice if the C++ standard put this value in the standard numeric_limits
#4 Updated by John Abbott almost 10 years ago
- Status changed from Feedback to Closed
- % Done changed from 90 to 100
#5 Updated by Anna Maria Bigatti almost 10 years ago
- Estimated time set to 4.00 h