diff options
Diffstat (limited to 'tests/tget_str.c')
-rw-r--r-- | tests/tget_str.c | 36 |
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); |