aboutsummaryrefslogtreecommitdiffstats
path: root/awkgram.y
diff options
context:
space:
mode:
Diffstat (limited to 'awkgram.y')
-rw-r--r--awkgram.y38
1 files changed, 31 insertions, 7 deletions
diff --git a/awkgram.y b/awkgram.y
index a5707429..30ac56a9 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -1977,15 +1977,39 @@ void
negate_num(NODE *n)
{
#ifdef HAVE_MPFR
- if (is_mpg_float(n)) {
- int tval;
- tval = mpfr_neg(n->mpg_numbr, n->mpg_numbr, ROUND_MODE);
- IEEE_FMT(n->mpg_numbr, tval);
- } else if (is_mpg_integer(n)) {
- mpz_neg(n->mpg_i, n->mpg_i);
- } else
+ int tval = 0;
#endif
+
+ if (! is_mpg_number(n)) {
n->numbr = -n->numbr;
+ return;
+ }
+
+#ifdef HAVE_MPFR
+ 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.
+ */
+
+ mpz_clear(n->mpg_i); /* release the integer storage */
+
+ /* Convert and fall through. */
+ tval = mpfr_set_d(n->mpg_numbr, 0.0, ROUND_MODE);
+ IEEE_FMT(n->mpg_numbr, tval);
+ 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
}
/* print_included_from --- print `Included from ..' file names and locations */