Mentions légales du service

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mpfr/mpfr
1 result
Show changes
Commits on Source (3)
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
@c Note that the 5 occurrences of the version string in this file @c Note that the 5 occurrences of the version string in this file
@c should be updated by the tools/update-version script. @c should be updated by the tools/update-version script.
@set VERSION 4.2.0 @set VERSION 4.2.0
@set UPDATED-MONTH January 2023 @set UPDATED-MONTH March 2023
@settitle GNU MPFR @value{VERSION} @settitle GNU MPFR @value{VERSION}
@synindex tp fn @synindex tp fn
@iftex @iftex
...@@ -1577,7 +1577,7 @@ Note that the input 0 is converted to @mm{+}0. ...@@ -1577,7 +1577,7 @@ Note that the input 0 is converted to @mm{+}0.
Set @var{rop} to the value of the string @var{s} in base @var{base}, Set @var{rop} to the value of the string @var{s} in base @var{base},
rounded in the direction @var{rnd}. rounded in the direction @var{rnd}.
See the documentation of @code{mpfr_strtofr} for a detailed description See the documentation of @code{mpfr_strtofr} for a detailed description
of the valid string formats. of @var{base} (with its special value 0) and the valid string formats.
Contrary to @code{mpfr_strtofr}, @code{mpfr_set_str} requires the Contrary to @code{mpfr_strtofr}, @code{mpfr_set_str} requires the
@emph{whole} string to represent a valid floating-point number. @emph{whole} string to represent a valid floating-point number.
@c Additionally, special values @c Additionally, special values
......
...@@ -176,6 +176,7 @@ special (void) ...@@ -176,6 +176,7 @@ special (void)
mpfr_t x, y; mpfr_t x, y;
int inex; int inex;
mpfr_exp_t emin, emax; mpfr_exp_t emin, emax;
int r;
emin = mpfr_get_emin (); emin = mpfr_get_emin ();
emax = mpfr_get_emax (); emax = mpfr_get_emax ();
...@@ -238,6 +239,18 @@ special (void) ...@@ -238,6 +239,18 @@ special (void)
MPFR_ASSERTN (mpfr_inf_p (y)); MPFR_ASSERTN (mpfr_inf_p (y));
MPFR_ASSERTN (mpfr_sgn (y) < 0); MPFR_ASSERTN (mpfr_sgn (y) < 0);
/* check log(1) is +0 whatever the rounding mode */
mpfr_set_ui (x, 1, MPFR_RNDN);
RND_LOOP (r)
{
mpfr_clear_flags ();
inex = test_log (y, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (__gmpfr_flags == 0);
MPFR_ASSERTN (inex == 0);
MPFR_ASSERTN (MPFR_IS_ZERO (y));
MPFR_ASSERTN (MPFR_IS_POS (y));
}
mpfr_clear (x); mpfr_clear (x);
mpfr_clear (y); mpfr_clear (y);
} }
......
...@@ -108,7 +108,7 @@ main (int argc, char *argv[]) ...@@ -108,7 +108,7 @@ main (int argc, char *argv[])
{ {
mpfr_t x, y; mpfr_t x, y;
unsigned int n; unsigned int n;
int inex; int inex, r;
tests_start_mpfr (); tests_start_mpfr ();
...@@ -117,50 +117,53 @@ main (int argc, char *argv[]) ...@@ -117,50 +117,53 @@ main (int argc, char *argv[])
mpfr_init2 (x, 53); mpfr_init2 (x, 53);
mpfr_init2 (y, 53); mpfr_init2 (y, 53);
/* check NaN */ RND_LOOP (r)
mpfr_set_nan (x);
inex = test_log10 (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0);
/* check Inf */
mpfr_set_inf (x, -1);
inex = test_log10 (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0);
mpfr_set_inf (x, 1);
inex = test_log10 (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (y) && mpfr_sgn (y) > 0 && inex == 0);
mpfr_set_ui (x, 0, MPFR_RNDN);
inex = test_log10 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0);
mpfr_set_ui (x, 0, MPFR_RNDN);
mpfr_neg (x, x, MPFR_RNDN);
inex = test_log10 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0);
/* check negative argument */
mpfr_set_si (x, -1, MPFR_RNDN);
inex = test_log10 (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0);
/* check log10(1) = 0 */
mpfr_set_ui (x, 1, MPFR_RNDN);
inex = test_log10 (y, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_cmp_ui (y, 0) == 0 && MPFR_IS_POS (y) && inex == 0);
/* check log10(10^n)=n */
mpfr_set_ui (x, 1, MPFR_RNDN);
for (n = 1; n <= 15; n++)
{ {
mpfr_mul_ui (x, x, 10, MPFR_RNDN); /* x = 10^n */ /* check NaN */
inex = test_log10 (y, x, MPFR_RNDN); mpfr_set_nan (x);
if (mpfr_cmp_ui (y, n)) inex = test_log10 (y, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0);
/* check Inf */
mpfr_set_inf (x, -1);
inex = test_log10 (y, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0);
mpfr_set_inf (x, 1);
inex = test_log10 (y, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (mpfr_inf_p (y) && mpfr_sgn (y) > 0 && inex == 0);
mpfr_set_ui (x, 0, MPFR_RNDN);
inex = test_log10 (x, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0);
mpfr_set_ui (x, 0, MPFR_RNDN);
mpfr_neg (x, x, MPFR_RNDN);
inex = test_log10 (x, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0);
/* check negative argument */
mpfr_set_si (x, -1, MPFR_RNDN);
inex = test_log10 (y, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (mpfr_nan_p (y) && inex == 0);
/* check log10(1) = 0 */
mpfr_set_ui (x, 1, MPFR_RNDN);
inex = test_log10 (y, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (MPFR_IS_ZERO (y) && MPFR_IS_POS (y) && inex == 0);
/* check log10(10^n)=n */
mpfr_set_ui (x, 1, MPFR_RNDN);
for (n = 1; n <= 15; n++)
{ {
printf ("log10(10^n) <> n for n=%u\n", n); mpfr_mul_ui (x, x, 10, MPFR_RNDN); /* x = 10^n */
exit (1); inex = test_log10 (y, x, (mpfr_rnd_t) r);
if (mpfr_cmp_ui (y, n))
{
printf ("log10(10^n) <> n for n=%u\n", n);
exit (1);
}
MPFR_ASSERTN (inex == 0);
} }
MPFR_ASSERTN (inex == 0);
} }
mpfr_clear (x); mpfr_clear (x);
......
...@@ -30,37 +30,40 @@ static void ...@@ -30,37 +30,40 @@ static void
special (void) special (void)
{ {
mpfr_t x; mpfr_t x;
int inex; int inex, r;
mpfr_init (x); mpfr_init (x);
mpfr_set_nan (x); RND_LOOP (r)
inex = mpfr_log2 (x, x, MPFR_RNDN); {
MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0); mpfr_set_nan (x);
inex = mpfr_log2 (x, x, (mpfr_rnd_t) r);
mpfr_set_inf (x, -1); MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0); mpfr_set_inf (x, -1);
inex = mpfr_log2 (x, x, (mpfr_rnd_t) r);
mpfr_set_inf (x, 1); MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) > 0 && inex == 0); mpfr_set_inf (x, 1);
inex = mpfr_log2 (x, x, (mpfr_rnd_t) r);
mpfr_set_ui (x, 0, MPFR_RNDN); MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) > 0 && inex == 0);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0); mpfr_set_ui (x, 0, MPFR_RNDN);
mpfr_set_ui (x, 0, MPFR_RNDN); inex = mpfr_log2 (x, x, (mpfr_rnd_t) r);
mpfr_neg (x, x, MPFR_RNDN); MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0);
inex = mpfr_log2 (x, x, MPFR_RNDN); mpfr_set_ui (x, 0, MPFR_RNDN);
MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0); mpfr_neg (x, x, MPFR_RNDN);
inex = mpfr_log2 (x, x, (mpfr_rnd_t) r);
mpfr_set_si (x, -1, MPFR_RNDN); MPFR_ASSERTN (mpfr_inf_p (x) && mpfr_sgn (x) < 0 && inex == 0);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0); mpfr_set_si (x, -1, MPFR_RNDN);
inex = mpfr_log2 (x, x, (mpfr_rnd_t) r);
mpfr_set_si (x, 1, MPFR_RNDN); MPFR_ASSERTN (mpfr_nan_p (x) && inex == 0);
inex = mpfr_log2 (x, x, MPFR_RNDN);
MPFR_ASSERTN (mpfr_cmp_ui (x, 0) == 0 && MPFR_IS_POS(x) && inex == 0); mpfr_set_si (x, 1, MPFR_RNDN);
inex = mpfr_log2 (x, x, (mpfr_rnd_t) r);
MPFR_ASSERTN (MPFR_IS_ZERO (x) && MPFR_IS_POS (x) && inex == 0);
}
mpfr_clear (x); mpfr_clear (x);
} }
......