summaryrefslogtreecommitdiff
path: root/awkgram.y
diff options
context:
space:
mode:
Diffstat (limited to 'awkgram.y')
-rw-r--r--awkgram.y31
1 files changed, 24 insertions, 7 deletions
diff --git a/awkgram.y b/awkgram.y
index 5846c134..fd83d6db 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -1964,16 +1964,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 */