4 ms·
I think it all depends what you meant by wider. I don't think anything will happen if you convert int8 to int16 (don't know swift so I don't know if it distingu
by takeda 11y ago
I think it all depends what you meant by wider. I don't think anything will happen if you convert int8 to int16 (don't know swift so I don't know if it distinguishes between those types), but if you for example do casting from integer to floats and vice versa (the author uses double as the universal type) and do some heavy calculations you can get wrong results.
This is because float/double is not really a wider type it is just a number representation that is not exact and just uses approximations so you actually are losing information.
- mnem 11y agoI'd generally limit wider to apply to the same, uh, type classes (there's probably a proper word) int8 to int16, float to double and so on. Casting between integers and floating point is pretty risky unless you're absolutely sure about your ranges and precision. Anything that does that silently gives me The Fear.