summaryrefslogtreecommitdiff
path: root/tests/tget_str.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-04-19 15:51:55 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2018-04-19 15:51:55 +0000
commit4ec86410d6774ba9c22dd8dbee3ee7378609f6a3 (patch)
tree8a2fe7eb2186caa8f2c97d551e562143e825a36b /tests/tget_str.c
parent46ead58b10497e9e112d1edd6a1f140becd217ee (diff)
downloadmpfr-4ec86410d6774ba9c22dd8dbee3ee7378609f6a3.tar.gz
Fixed an issue with mpfr_get_str: The number 1 of significant digits
output in the string is now fully supported, i.e. * the value 1 can be provided for n (4th argument); * if n = 0, then the number of significant digits in the output string can now be 1, as already implied by the documentation (but the code was increasing it to 2). Changes: * doc/mpfr.texi: updated mpfr_get_str description to accept n = 1. * src/get_str.c: fixed the code as explained above (for n = 0, removed the increase to 2, and removed an MPFR_ASSERTN). * tests/tget_str.c: added tests. (merged changesets from the trunk: r12430 on tests/tget_str.c only; r12432,12434,12440) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/4.0@12642 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tget_str.c')
-rw-r--r--tests/tget_str.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/tget_str.c b/tests/tget_str.c
index b49d3a013..2ede2c07e 100644
--- a/tests/tget_str.c
+++ b/tests/tget_str.c
@@ -1267,6 +1267,41 @@ check_negative_base (void)
#define ITER 1000
+static void
+coverage (void)
+{
+ mpfr_t x;
+ char s[42];
+ mpfr_exp_t e;
+ int b = 3;
+ size_t m = 40;
+
+ mpfr_init2 (x, 128);
+
+ /* exercise corner case in mpfr_get_str_aux: exact case (e < 0), where r
+ rounds to a power of 2, and f is a multiple of GMP_NUMB_BITS */
+ mpfr_set_ui_2exp (x, 1, 64, MPFR_RNDU);
+ mpfr_nextbelow (x);
+ /* x = 2^64 - 2^(-64) */
+ mpfr_get_str (s, &e, b, m, x, MPFR_RNDU);
+ /* s is the base-3 string for 6148914691236517206 (in base 10) */
+ MPFR_ASSERTN(strcmp (s, "1111222002212212010121102012021021021200") == 0);
+ MPFR_ASSERTN(e == 41);
+
+ /* exercise corner case in mpfr_get_str: input is m=0, then it is changed
+ to m=1 */
+ mpfr_set_prec (x, 1);
+ mpfr_set_ui (x, 1, MPFR_RNDN);
+ mpfr_get_str (s, &e, 2, 0, x, MPFR_RNDN);
+ MPFR_ASSERTN(strcmp (s, "1") == 0);
+ MPFR_ASSERTN(e == 1);
+ mpfr_get_str (s, &e, 2, 1, x, MPFR_RNDN);
+ MPFR_ASSERTN(strcmp (s, "1") == 0);
+ MPFR_ASSERTN(e == 1);
+
+ mpfr_clear (x);
+}
+
int
main (int argc, char *argv[])
{
@@ -1281,6 +1316,7 @@ main (int argc, char *argv[])
tests_start_mpfr ();
+ coverage ();
check_small ();
check_special (2, 2);