diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-01-19 21:36:37 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-01-19 21:36:37 +0200 |
commit | 20ca1d1ba6e46f116e2dc169d263fd548b9bd074 (patch) | |
tree | 74d46c4cf0ecf8704df7d4dde7138ee0e131d1ec /awkgram.c | |
parent | 9092450b4459af490e4d52ad3188d3282f36f726 (diff) | |
download | egawk-20ca1d1ba6e46f116e2dc169d263fd548b9bd074.tar.gz egawk-20ca1d1ba6e46f116e2dc169d263fd548b9bd074.tar.bz2 egawk-20ca1d1ba6e46f116e2dc169d263fd548b9bd074.zip |
Fix -0 for MPFR.
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 */ |