Description
Regardless of the outcome of issue #1074, we should consider suffixing .0
for FP strings with no fractional part. A bare numeric literal with no exponent or decimal is typically an integer literal, not a float literal. This presents issues in various ways:
-0
looks strange to programmers. Only the floating-point zero can be negative.-0
is much less likely to round-trip than-0.0
.- Sending a value from Rust to a dynamic language with a separate integer type (e.g. Python / Ruby / Racket) is hazardous. The number may be parsed as a float or an integer, and if the code, for instance, divides numbers by
2
, there may be unexpected truncation. Debug
's recent RFC 640 indicates that, "when it is feasible to do so, debugging output should match Rust syntax." While, say,4.0
is a valid FP value in Rust,4
is not.
The .0
suffix is reasonably widespread, though not as ubiquitous as minus zero. Exceptions include C# and Go. OCaml prints a bare .
suffix, as in 42.
.
Our JSON serializer suffixes .0
to the result of Display
. I feel that this should be the default behavior.
It might also make sense to add the .0
suffix even for floats with an exponent, though the need is less clear. It is somewhat more consistent, and it matches Haskell, Java, and Ruby. Thus far, I know that Erlang's REPL does not accept 1e30
but does accept 1.0e30
. I expect most systems to treat 1e30
and 1.0e30
equivalently.