diff options
-rw-r--r-- | src/set_d64.c | 2 | ||||
-rw-r--r-- | tests/tget_set_d64.c | 46 |
2 files changed, 47 insertions, 1 deletions
diff --git a/src/set_d64.c b/src/set_d64.c index 921f7b05e..8e33e5d93 100644 --- a/src/set_d64.c +++ b/src/set_d64.c @@ -425,7 +425,7 @@ mpfr_set_decimal64 (mpfr_ptr r, _Decimal64 d, mpfr_rnd_t rnd_mode) 1 character for terminating \0. */ decimal64_to_string (s, d); - return mpfr_set_str (r, s, 10, rnd_mode); + return mpfr_strtofr (r, s, NULL, 10, rnd_mode); } #endif /* MPFR_WANT_DECIMAL_FLOATS */ diff --git a/tests/tget_set_d64.c b/tests/tget_set_d64.c index a5f149b6b..e829aab80 100644 --- a/tests/tget_set_d64.c +++ b/tests/tget_set_d64.c @@ -419,6 +419,51 @@ check_tiny (void) mpfr_clear (x); } +static void +powers_of_10 (void) +{ + mpfr_t x1, x2; + int inex1, inex2; + mpfr_flags_t flags1, flags2; + _Decimal64 d[2]; + int i, neg, rnd; + + mpfr_inits2 (200, x1, x2, (mpfr_ptr) 0); + for (i = 0, d[0] = 1, d[1] = 1; i < 150; i++, d[0] *= 10, d[1] /= 10) + for (neg = 0; neg <= 1; neg++) + RND_LOOP_NO_RNDF (rnd) + { + inex1 = mpfr_set_si (x1, neg ? -i : i, MPFR_RNDN); + MPFR_ASSERTN (inex1 == 0); + + mpfr_clear_flags (); + inex1 = mpfr_exp10 (x1, x1, (mpfr_rnd_t) rnd); + flags1 = __gmpfr_flags; + + mpfr_clear_flags (); + inex2 = mpfr_set_decimal64 (x2, d[neg], (mpfr_rnd_t) rnd); + flags2 = __gmpfr_flags; + + if (!(mpfr_equal_p (x1, x2) && + SAME_SIGN (inex1, inex2) && + flags1 == flags2)) + { + printf ("Error in powers_of_10 for i=%d, neg=%d, %s\n", + i, neg, mpfr_print_rnd_mode ((mpfr_rnd_t) rnd)); + printf ("Expected "); + mpfr_dump (x1); + printf ("with inex = %d and flags =", inex1); + flags_out (flags1); + printf ("Got "); + mpfr_dump (x2); + printf ("with inex = %d and flags =", inex2); + flags_out (flags2); + exit (1); + } + } + mpfr_clears (x1, x2, (mpfr_ptr) 0); +} + int main (void) { @@ -439,6 +484,7 @@ main (void) check_overflow (); #endif check_tiny (); + powers_of_10 (); tests_end_mpfr (); return 0; |