Bug 3219 – Inaccurate std.conv.to!(numeric)(numeric) error messages

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-07-31T05:27:00Z
Last change time
2015-06-09T01:28:07Z
Assigned to
andrei
Creator
bugzilla

Comments

Comment #0 by bugzilla — 2009-07-31T05:27:25Z
The errors raised by the numeric-numeric conversion function in std.conv are inaccurate in two ways: 1. Both underflowing and overflowing conversions raise a ConversionOverflowError, with the following respective messages presented to the user: std.conv.ConvOverflowError: Error: overflow Conversion underflow std.conv.ConvOverflowError: Error: overflow Conversion overflow 2. Converting a floating-point NaN to an integer type gives an underflow error. Suggestions for simple fixes: 1. At the very least, the "overflow" string which is added to both over- and underflow errors should be removed from ConvOverflowError. 2. Put the following at the top of the "to" function definition: static if (isFloatingPoint!S && !isFloatingPoint!T) if (isNaN(value)) ConvOverflowError.raise("Cannot convert " ~S.stringof~".nan to "~T.stringof); (Of course, it is arguable whether the slightly more accurate error message is worth the performance penalty of the additional check...)