A similar question Long in Float, why? here does not answer what I am searching for.
C# standard allows implicit conversion from long to float.
But any long greater than 2^24 when represented as a float is bound to lose its ‘value’.
C# standard clearly states that long to float conversion may lose ‘precision’ but will never lose ‘magnitude’.
My Questions are
- In reference to integral types what is meant by ‘precision’ and ‘magnitude’. Isn’t number n totally different from number n+1 unlike real numbers where 3.333333 and 3.333329 may be considered close enough for a calculation (i.e. depending on what precision programmer wants)
- Isn’t allowing implicit conversion from long to float an invitation to subtle bugs as it can lead a long to ‘silently’ lose value (as a C# programmer I am accustomed to compiler doing an excellent job in guarding me against such issues)
So what could have been the rationale of C# language design team in allowing this conversion as implicit? What is it that I am missing here that justifies implicit conversion from long to float?
In general, floating point numbers don’t represent many numbers exactly. By their nature they are inexact and subject to precision errors. It really doesn’t add value to warn you about what is always the case with floating point.