4 ms·
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
by pacaro 11y ago
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?
- nadohs 11y agoI 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...
- p0nce 11y ago1.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.
- anon4 11y agoIf 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.
- malkia 11y agoI'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
- coldtea 11y ago>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.