Converting from Float64 to Int64 works fine if the number is an integer, otherwise a InexactError is thrown, and the user is required to use a function such as round or floor to perform the conversion in general.
There are Int64 numbers that cannot be represented with enough accuracy in Float64. In a way, it’s the same problem: one type can represent values with more accuracy than the other, accuracy is being lost in the conversion. Shouldn’t the same InexactError be throw in this case?
This has practical importance: if you represent dates or geographical coordinates you often have numbers varying around a large bias, and it may work fine as fixed-point integers, but converting to Float will lose precision.
we don’t have to throw an error when its documented condition is met. It could be handled another way, or we could opt out in exception handling.
Converting to a type with lower precision is accepted as silent or warned approximation in many languages. Conversions to lower precision floating point logically could’ve gone the way you’re proposing, but it’s already unusual to even throw InexactErrors in this many situations.
The basic argument here is that construction of floating-point values, whether from integers, or rationals like 1//3, arithmetic expressions like 1/3, or literal values like 0.1, is commonly understood to involve rounding. Requiring the rounding to be explicit just in the constructor/convert context would therefore be unnecessarily awkward.
That’s not the case with types like Int or Rational, where operations are understood to be exact unless rounding is requested explicitly.
Thanks everyone for the insightful comments, I couldn’t find the previous discussion. I guess in the end rounding is part of life when your result is a float, and the fact you can exactly convert some floats to int is actually kind of a quirk.