Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50885 Signed-off-by: Lauri Kenttä lauri.kentta@gmail.com
--- v2: More compact version.
dlls/msvcrt/math.c | 18 ++++++++---------- dlls/msvcrt/tests/printf.c | 4 ++++ 2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/dlls/msvcrt/math.c b/dlls/msvcrt/math.c index 6b2d08a8294..eb25b578a2b 100644 --- a/dlls/msvcrt/math.c +++ b/dlls/msvcrt/math.c @@ -2585,7 +2585,7 @@ char * CDECL _ecvt( double number, int ndigits, int *decpt, int *sign ) if (!data->efcvt_buffer) data->efcvt_buffer = malloc( 80 ); /* ought to be enough */
- if( number < 0) { + if (number < 0 || (number == 0 && signbit(number))) { *sign = TRUE; number = -number; } else @@ -2648,7 +2648,7 @@ int CDECL _ecvt_s( char *buffer, size_t length, double number, int ndigits, int if( prec < 1) prec = 2; result = malloc(prec + 7);
- if( number < 0) { + if (number < 0 || (number == 0 && signbit(number))) { *sign = TRUE; number = -number; } else @@ -2690,10 +2690,9 @@ char * CDECL _fcvt( double number, int ndigits, int *decpt, int *sign ) if (!data->efcvt_buffer) data->efcvt_buffer = malloc( 80 ); /* ought to be enough */
- if (number < 0) - { - *sign = 1; - number = -number; + if (number < 0 || (number == 0 && signbit(number))) { + *sign = 1; + number = -number; } else *sign = 0;
stop = _snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number); @@ -2774,10 +2773,9 @@ int CDECL _fcvt_s(char* outbuffer, size_t size, double number, int ndigits, int return EINVAL; }
- if (number < 0) - { - *sign = 1; - number = -number; + if (number < 0 || (number == 0 && signbit(number))) { + *sign = 1; + number = -number; } else *sign = 0;
stop = _snprintf(buf, 80, "%.*f", ndigits < 0 ? 0 : ndigits, number); diff --git a/dlls/msvcrt/tests/printf.c b/dlls/msvcrt/tests/printf.c index 8960671f23e..14fd75d2b3c 100644 --- a/dlls/msvcrt/tests/printf.c +++ b/dlls/msvcrt/tests/printf.c @@ -647,6 +647,10 @@ static struct { { 0.0, 5, "00000", "00000", 0, 0, 0 }, { 0.0, 0, "", "", 0, 0, 0 }, { 0.0, -1, "", "", 0, 0, 0 }, + /* -0.0 with different precisions */ + { -0.0, 5, "00000", "00000", 0, 0, 1 }, + { -0.0, 0, "", "", 0, 0, 1 }, + { -0.0, -1, "", "", 0, 0, 1 }, /* Numbers > 1.0 with 0 or -ve precision */ { -123.0001, 0, "", "123", 3, 3, 1 }, { -123.0001, -1, "", "12", 3, 3, 1 },
Hi Lauri,
I've sent modified version of your patch (so it also handles e.g. -NAN): https://source.winehq.org/patches/data/203047
Thanks, Piotr
On 2021-04-01 22:00, Piotr Caban wrote:
Hi Lauri,
I've sent modified version of your patch (so it also handles e.g. -NAN): https://source.winehq.org/patches/data/203047
Looks good! I was focused only on my own use case, but evidently there was a lot more to do.
It's nice to send occasional patches when the response is so helpful and constructive. Thanks to all wine-devel people who make this happen.