Menu

#732 wrong exponent digits count with __USE_MINGW_ANSI_STDIO

v1.0 (example)
closed-fixed
LIU Hao
None
5
2018-05-06
2018-05-05
lazka
No

Using __USE_MINGW_ANSI_STDIO I would expect printf etc to follow what POSIX systems and MSVC2015+ do (see https://docs.microsoft.com/en-us/cpp/c-runtime-library/set-output-format) and only print two digits for the exponent if not more are required.

Example:

#define __USE_MINGW_ANSI_STDIO 1
#include <stdio.h>
int main(void) {
    printf("%0.e\n", 1e99);
    return 0;
}

Expected:

1e+99

Actual:

1e+099

Discussion

  • LIU Hao

    LIU Hao - 2018-05-05

    The C11 standard (draft) says

    e,E A double argument representing a floating-point number is converted in the
    style [−]d.ddd e±dd, ... The exponent always contains at least two digits,
    and only as many more digits as necessary to represent the exponent. If the
    value is zero, the exponent is zero.

    So having more digits seems non-compliant behavior to me.

     
  • LIU Hao

    LIU Hao - 2018-05-05

    Read mingw-w64-crt/stdio/mingw_pformat.c on master, line 186:

    #ifdef _WIN32
    /*
     * The Microsoft standard for printing `%e' format exponents is
     * with a minimum of three digits, unless explicitly set otherwise,
     * by a prior invocation of the `_set_output_format()' function.
     *
     * The following macro allows us to replicate this behaviour.
     */
    # define PFORMAT_MINEXP    __pformat_exponent_digits()
    
     
  • lazka

    lazka - 2018-05-05

    Does this mean it's on purpose?

     
    • LIU Hao

      LIU Hao - 2018-05-06

      Yes.

       
      • lazka

        lazka - 2018-05-06

        OK. With _set_output_format gone and newer MSVC being C99 compliant for this case this seems to ge against the goals of __USE_MINGW_ANSI_STDIO imo.

         
  • LIU Hao

    LIU Hao - 2018-05-06

    Microsoft doc says the _set_output_format() function is no longer available since 2017 and now the default behavior outputs at least 2 digits for the exponent rather than 3. I think this should be changed. Looking forward to others' opinion.

     

    Last edit: LIU Hao 2018-05-06
  • LIU Hao

    LIU Hao - 2018-05-06
    • status: open --> open-accepted
    • assigned_to: LH_Mouse
     
  • LIU Hao

    LIU Hao - 2018-05-06
    • status: open-accepted --> closed-fixed
     
  • LIU Hao

    LIU Hao - 2018-05-06

    Fixed on master.

     

Log in to post a comment.