diff options
Diffstat (limited to 'awkgram.c')
-rw-r--r-- | awkgram.c | 31 |
1 files changed, 24 insertions, 7 deletions
@@ -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 */ |