aboutsummaryrefslogtreecommitdiffstats
path: root/command.y
diff options
context:
space:
mode:
authorjohn haque <j.eh@mchsi.com>2012-03-19 04:30:00 -0500
committerjohn haque <j.eh@mchsi.com>2012-03-19 04:30:00 -0500
commit40645cb3cb155eb59dd745af4ae0e06e729c8eb1 (patch)
tree1c24a9a6cb2ac9acc985b3f4667c7139c10c4525 /command.y
parentb5431a4825e325c61f4043e4d25e47d7891c228c (diff)
downloadegawk-40645cb3cb155eb59dd745af4ae0e06e729c8eb1.tar.gz
egawk-40645cb3cb155eb59dd745af4ae0e06e729c8eb1.tar.bz2
egawk-40645cb3cb155eb59dd745af4ae0e06e729c8eb1.zip
Add arbitrary-precision arithmetic on integers.
Diffstat (limited to 'command.y')
-rw-r--r--command.y13
1 files changed, 11 insertions, 2 deletions
diff --git a/command.y b/command.y
index e36497ad..cb5707c6 100644
--- a/command.y
+++ b/command.y
@@ -1246,8 +1246,17 @@ err:
errno = 0;
#ifdef HAVE_MPFR
if (do_mpfr) {
- r = mpg_node();
- (void) mpfr_strtofr(r->mpg_numbr, tokstart, & lexptr, 0, RND_MODE);
+ int tval;
+ r = mpg_float();
+ tval = mpfr_strtofr(r->mpg_numbr, tokstart, & lexptr, 0, RND_MODE);
+ IEEE_FMT(r->mpg_numbr, tval);
+ if (mpfr_integer_p(r->mpg_numbr)) {
+ /* integral value, convert to a GMP type. */
+ NODE *tmp = r;
+ r = mpg_integer();
+ mpfr_get_z(r->mpg_i, tmp->mpg_numbr, MPFR_RNDZ);
+ unref(tmp);
+ }
} else
#endif
r = make_number(strtod(tokstart, & lexptr));