4 ms·
> Instead of barfing when assigning a Float to an Int, just auto round? Because you can’t really round many floats to Int. A float can be larger than 10^38. I
by Someone 3y ago
> Instead of barfing when assigning a Float to an Int, just auto round?
Because you can’t really round many floats to Int.
A float can be larger than 10^38. If you ‘round’ that to a 64-bit signed integer, you have to return something that’s smaller than 10^19.
For doubles, it’s even worse. They can be larger than 10^308.
I think that indicates that “just auto round” isn’t an option.
The option “if a reasonable conversion exists, make it, otherwise bail out” IMO is a lot worse than having a way to try that conversion and somehow indicate to the programmer when it failed.