[swift-evolution] floating point numbers implicit conversion

Ted F.A. van Gaalen tedvgiosdev at gmail.com
Mon Jun 19 16:00:16 CDT 2017


if it were possible, I would only use one floating point type 
in my app, however FP conversions are needed often, 
because of heavy usage of library functions
e.g. SceneKit  that all work with different floating point types..
Programmers should be aware of the implications of conversions
e.g. learn and test these in playground if not completely understood...
TedvG
> On 19. Jun 2017, at 22:44, John McCall <rjmccall at apple.com> wrote:
> 
>> On Jun 19, 2017, at 1:58 PM, Stephen Canon via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> 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
>> 	result = temp + double
>> 
>> 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).
> 
> I don't!  At least not for floating point.  It is important for both reliable behavior and performance that programmers understand and minimize the conversions they do between different floating-point types.
> 
> John.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170619/17680847/attachment.html>


More information about the swift-evolution mailing list