Skip to content

possible %g minor non-compliance #48

Closed

Description

@ledvinap

There is minor problem with %g specifier:

from https://www.gnu.org/software/libc/manual/html_node/Floating_002dPoint-Conversions.html#Floating_002dPoint-Conversions

The ‘%g’ and ‘%G’ conversions print the argument in the style of ‘%e’ or ‘%E’ (respectively) if the exponent would be less than -4 or greater than or equal to the precision; otherwise they use the ‘%f’ style. A precision of 0, is taken as 1. Trailing zeros are removed from the fractional portion of the result and a decimal-point character appears only if it is followed by a digit.

printf("%0-15.3g", -42.); :

"-42.0          "
glibc printf:
"-42            "

It seems to me that %g should use shortest representation, precision is only upper limit, # modifier may be used if decimal point is requested (unimplemented now)
(https://stackoverflow.com/questions/30658919/the-precision-of-printf-with-specifier-g)

Activity

  1. eyalroz commented on Aug 4, 2021

    @eyalroz
    Collaborator

    See also issue #75.

    Seems to be resolved by commit 84e66ae on my fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions