Patrick R. Michaud wrote:
>                                            But that's a language
>specification call that someone outside of Rakudo probably needs
>to make.

doc/Type/Str.pod (which I checked before reporting the bug) says it's
"mostly identical to the C library sprintf function", and doesn't describe
any relevant derogation from the C definition.  C practice is to show
the value actually represented by the floating-point value, correctly
rounded to the output precision.  If you want the formal definition, the
most up-to-date version of the C standard that I have (not very recent,
but I don't expect this to have changed) says

# f,F    A double argument representing a (finite) floating-point number
#        is converted to decimal notation in the style "[-]ddd.ddd",
#        where the number of digits after the decimal-point character
#        is equal to the precision specification.  If the precision is
#        missing, it is taken as 6; if the precision is zero and the
#        "#" flag is not specified, no decimal-point character appears.
#        If a decimal-point character appears, at least one digit
#        appears before it.  The value is rounded to the appropriate
#        number of digits.

This is slightly less clear than I expected: there's a tiny bit of room
to argue about what the "appropriate number of digits" is.  In context
I think it's clear enough that the appropriate number is the number of
digits following the decimal point, which the standard has just spent
half the paragraph describing.  The standard does go on to make clear
that it doesn't require the rounding to be correct, though.

-zefram

Reply via email to