From 20ca1d1ba6e46f116e2dc169d263fd548b9bd074 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 19 Jan 2014 21:36:37 +0200 Subject: Fix -0 for MPFR. --- awkgram.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'awkgram.c') diff --git a/awkgram.c b/awkgram.c index 7eff2f11..657a1627 100644 --- a/awkgram.c +++ b/awkgram.c @@ -4512,16 +4512,33 @@ getfname(NODE *(*fptr)(int)) void negate_num(NODE *n) { + int tval = 0; + + if (! is_mpg_number(n)) + n->numbr = -n->numbr; #ifdef HAVE_MPFR - if (is_mpg_float(n)) { - int tval; - tval = mpfr_neg(n->mpg_numbr, n->mpg_numbr, ROUND_MODE); + else if (is_mpg_integer(n)) { + if (! iszero(n)) { + mpz_neg(n->mpg_i, n->mpg_i); + return; + } + + /* + * 0 --> -0 conversion. Requires turning the MPG integer + * into an MPFR float. + * + * So, convert and fall through. + */ + tval = mpfr_set_d(n->mpg_numbr, 0.0, ROUND_MODE); IEEE_FMT(n->mpg_numbr, tval); - } else if (is_mpg_integer(n)) { - mpz_neg(n->mpg_i, n->mpg_i); - } else + n->flags &= ~MPZN; + n->flags |= MPFN; + } + + /* mpfr float case */ + tval = mpfr_neg(n->mpg_numbr, n->mpg_numbr, ROUND_MODE); + IEEE_FMT(n->mpg_numbr, tval); #endif - n->numbr = -n->numbr; } /* print_included_from --- print `Included from ..' file names and locations */ -- cgit v1.2.3