[swift-evolution] floating point numbers implicit conversion
Ted F.A. van Gaalen
tedvgiosdev at gmail.com
Mon Jun 19 14:34:29 CDT 2017
> On 19. Jun 2017, at 19:58, Stephen Canon <scanon at apple.com> wrote:
>> On Jun 19, 2017, at 11:46 AM, Ted F.A. van Gaalen via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> var result: Float = 0.0
>> result = float * integer * uint8 + double
>> // here, all operands should be implicitly promoted to Double before the complete expression evaluation.
> You would have this produce different results than:
> let temp = float * integer * uint8
“temp” is now a Float
> result = temp + double
“temp" being implicitly converted to a Double before expression evaluation
(assuming the var “result” is still the Float declared in my example)
after conversion, the expression would be implicitly, type wise
float = Float( double + double)
Apart perhaps from small floating point inherent imprecision, I don’t see much difference...
am I missing something?
> That would be extremely surprising to many unsuspecting users.
> Don’t get me wrong; I *really want* implicit promotions (I proposed one scheme for them way back when Swift was first unveiled publicly). But there’s a lot more subtlety around them than it seems (for example the C and C++ implicit promotion rules can easily be described on a half-sheet of paper, but are the source of *innumerable* bugs). I would rather have no implicit promotions than half-baked implicit promotions.
I C what you mean. yes, implicit conversion can produce unexpected results, yes.
Have to be used either with common sense or a lot of debugging or both :o)
But that’s the case with many programming language features...
(no debuggers in ca 1980, IDEs are pure luxury :o)
> – Steve
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution