Re: Should %d round?
- Posted by Vinoba Mar 20, 2012
- 1748 views
The logic:
In ASCII, ANSI, UNICODE, the characters 0-9 and the decimal point are characters.
Unlike most languages, Euphoria has chosen the route of recognizing literals and numeric characters as one, at least to start with and only later recognize the special characters as worthy of mathematical manipulations.
If we take "3.99999" as a string of literals only, we can safely say we want 1 character "3" or THREE characters "3.9".
However, the moment we recognize the decimal point as something special and meaningful mathematically, we are required to recognize the whole string as a number which needs to be interpreted and portrayed rationally in its full or abbreviated form.
Another argument for a more rational and practical approach is the fact of calculations occurring in hex and these are represented in decimal format.
It is conceivable that some calculations may end up as 3.99999 when actually the number might best be represented as 3.99998 or 4.00000. Therefore, in portraying the result of the previous hex calculations as 3.99999 is at best an approximation. Somebody might argue that it was 3.99999482397, but that it only reinforces my argument that very often the literal "3.99999" has a value not quite 3.99999
Hence the need for a rational mathematically sound and practical approach.