diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-06-19 13:10:42 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2018-06-19 13:10:42 +0000 |
commit | dad9867b60449ef9072563fc8fe7cb483ed8e6a3 (patch) | |
tree | a251b569e4f685eb63db9a36316281982f0baa1b | |
parent | a79bbd490566a7141fe3d7cd3d9aaffd5af48815 (diff) | |
download | mpfr-dad9867b60449ef9072563fc8fe7cb483ed8e6a3.tar.gz |
[src/set_d64.c] Fixed ternary value, which was always 0. This is done by
using mpfr_strtofr instead of mpfr_set_str (merged part of changeset
r12783 from the trunk).
[tests/tget_set_d64.c] Added tests on powers of 10, checking the ternary
value in particular (merged part of changeset r12782 from the trunk).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/4.0@12786 280ebfd0-de03-0410-8827-d642c229c3f4
-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; |