D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3219 - Inaccurate std.conv.to!(numeric)(numeric) error messages
Summary: Inaccurate std.conv.to!(numeric)(numeric) error messages
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-31 05:27 UTC by Lars T. Kyllingstad
Modified: 2015-06-09 01:28 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lars T. Kyllingstad 2009-07-31 05:27:25 UTC
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...)