Hacker News new | past | comments | ask | show | jobs | submit login

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?




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...


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.


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.


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


>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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: