News for hackers. Stuff that matters.
Re:Cast-Free Arithmetic in Swift by pacaro on Monday October 12, 2015 @12:37PM (#10375605)
I understand the spirit of exploration and fun that this was done with, however the author talks of using this in "production". This scares me. These types are not interchangeable.

I would love to see a disclaimer and/or a discussion of what can go wrong

EDIT: If I add the floats 1.5 and 1.5 to get an integer, is the result 2 or 3?

Re:Cast-Free Arithmetic in Swift by nadohs on Monday October 12, 2015 @01:34PM (#10375938)
I use the dot property conversion, not the overloading in general use. I also have such reservations about using overloading for casting in production. What I do use, is the series of extensions for single letter dot property conversions, the extensions without the protocol extending, that I also used in Swift 1.2. Sorry if that was unclear...
Re:Cast-Free Arithmetic in Swift by p0nce on Monday October 12, 2015 @02:51PM (#10376328)
1.5 has an exact representation in floating-point, so adding 1.5 + 1.5 is always going to give you 3.0 in floating-point, also exactly represented.

Then whatever the type of integer rounding you do, you will get a solid 3.

Re:Cast-Free Arithmetic in Swift by anon4 on Monday October 12, 2015 @02:55PM (#10376354)
If you need to convert float to int, use an explicit rounding mode. Then adding 0.1f (or rather the closest fp approximation) ten times will round up to 10.
Re:Cast-Free Arithmetic in Swift by malkia on Monday October 12, 2015 @03:15PM (#10376451)
I've read that as do 1.4 + 1.4 give you 2 or 3 - if you cast 1.4 to int first, you'll get 1 + 1 = 2, but otherwise 1.4+1.4 = 2.8 -> to int = 3
Re:Cast-Free Arithmetic in Swift by coldtea on Monday October 12, 2015 @04:01PM (#10376667)
>I understand the spirit of exploration and fun that this was done with, however the author talks of using this in "production". This scares me.

Not all producton is critical.