From 87ae66d706af46fdf87f37a95810ec98ebccfe6f Mon Sep 17 00:00:00 2001 From: Doug Currie Date: Sat, 23 Jan 2016 16:30:40 -0500 Subject: [PATCH] Fix roundtrip -0.0 --- contrib/10.roundtrip/emyg_dtoa.c | 8 ++------ contrib/10.roundtrip/t/roundtrip.scm | 6 ++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/contrib/10.roundtrip/emyg_dtoa.c b/contrib/10.roundtrip/emyg_dtoa.c index ec76a1c2..8a932628 100644 --- a/contrib/10.roundtrip/emyg_dtoa.c +++ b/contrib/10.roundtrip/emyg_dtoa.c @@ -426,12 +426,8 @@ void emyg_dtoa (double value, char* buffer) { strcpy(buffer, signbit(value) ? "-inf.0" : "+inf.0"); else if (isnan(value)) strcpy(buffer, signbit(value) ? "-nan.0" : "+nan.0"); - else if (value == 0) { - buffer[0] = '0'; - buffer[1] = '.'; - buffer[2] = '0'; - buffer[3] = '\0'; - } + else if (value == 0) + strcpy(buffer, signbit(value) ? "-0.0" : "0.0"); else { if (value < 0) { *buffer++ = '-'; diff --git a/contrib/10.roundtrip/t/roundtrip.scm b/contrib/10.roundtrip/t/roundtrip.scm index ecbde357..f5568087 100644 --- a/contrib/10.roundtrip/t/roundtrip.scm +++ b/contrib/10.roundtrip/t/roundtrip.scm @@ -17,6 +17,12 @@ (test #t (rountrip-ok +inf.0)) +(test #t (rountrip-ok +0.0)) + +(test #t (rountrip-ok -0.0)) + +(test #t (rountrip-ok 0.0)) + (test -inf.0 (string->number "-inf.0")) (test +inf.0 (string->number "+inf.0"))