[swift-evolution] [swift-evolution-announce] [Review] SE-0080: Failable Numeric Conversion Initializers

Dave Abrahams dabrahams at apple.com
Fri May 6 19:54:26 CDT 2016


on Wed May 04 2016, Colin Barrett <swift-evolution at swift.org> wrote:

>> Swift numeric types all currently have a family of conversion
> initializers. In many use cases they leave a lot to be
> desired. Initializing an integer type with a floating point value will
> truncate any fractional portion of the number. Initializing with an
> out-of-range value traps.
>
> Have you considered whether it makes sense to keep these around? Maybe
> the failable ones should be the default, and give the other ones a
> more descriptive 1st argument label.

That would overturn Swift's fundamental programming model for numerics,
which is based on the fact that, to a first approximation, everybody
codes, **and wants to continue coding** as though their Int is really an
unbounded integer and their Double is an unbounded real number with
unlimited precision.  We very intentionally make the limitations of our
numeric types observable, but also not in-your-face for basic operations.

If we were to go this route, we would also make you unwrap the result of
x + 1 because it might overflow.


-- 
Dave



More information about the swift-evolution mailing list