summaryrefslogtreecommitdiff
path: root/tests/tlog2.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-11-30 13:37:37 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2001-11-30 13:37:37 +0000
commit538b931a3b879b73798dcbe4fd9a979a95174cd4 (patch)
tree713fa59db50eadb7a0886a390baaebda16331f8a /tests/tlog2.c
parent2a906d4c9bbb339a55823e51fa92e2e78fdbb917 (diff)
downloadmpfr-538b931a3b879b73798dcbe4fd9a979a95174cd4.tar.gz
start tests with precision 2 instead of 1
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@1606 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tlog2.c')
-rw-r--r--tests/tlog2.c83
1 files changed, 75 insertions, 8 deletions
diff --git a/tests/tlog2.c b/tests/tlog2.c
index 3d9dc721a..b3b120d61 100644
--- a/tests/tlog2.c
+++ b/tests/tlog2.c
@@ -26,6 +26,49 @@ MA 02111-1307, USA. */
/* tlog2 [prec] [rnd] [0 = no print] */
+extern mp_prec_t __mpfr_const_log2_prec;
+void check _PROTO ((mp_prec_t, mp_prec_t));
+
+void
+check (mp_prec_t p0, mp_prec_t p1)
+{
+ mpfr_t x, y, z;
+ mp_rnd_t rnd;
+
+ mpfr_init (x);
+ mpfr_init (y);
+ mpfr_init2 (z, p1 + 10);
+ mpfr_const_log2 (z, GMP_RNDN);
+ __mpfr_const_log2_prec = 1;
+
+ for (; p0<=p1; p0++)
+ {
+ mpfr_set_prec (x, p0);
+ mpfr_set_prec (y, p0);
+ for (rnd = 0; rnd < 4; rnd++)
+ {
+ mpfr_const_log2 (x, rnd);
+ mpfr_set (y, z, rnd);
+ if (mpfr_cmp (x, y) && mpfr_can_round (z, mpfr_get_prec(z), GMP_RNDN,
+ rnd, p0))
+ {
+ fprintf (stderr, "mpfr_const_log2 fails for prec=%u, rnd=%s\n",
+ (unsigned int) p0, mpfr_print_rnd_mode (rnd));
+ fprintf (stderr, "expected ");
+ mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
+ fprintf (stderr, "\ngot ");
+ mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
+ fprintf (stderr, "\n");
+ exit (1);
+ }
+ }
+ }
+
+ mpfr_clear (x);
+ mpfr_clear (y);
+ mpfr_clear (z);
+}
+
int
main (int argc, char *argv[])
{
@@ -35,14 +78,38 @@ main (int argc, char *argv[])
p = (argc>1) ? atoi(argv[1]) : 53;
rnd = (argc>2) ? atoi(argv[2]) : GMP_RNDZ;
- mpfr_init2(x, p);
- mpfr_const_log2(x, rnd);
- if (argc>=2) {
- printf("log(2)="); mpfr_out_str(stdout, 10, 0, x, rnd); putchar('\n');
- }
- else if (mpfr_get_d(x) != 6.9314718055994530941e-1) {
- fprintf(stderr, "mpfr_const_log2 failed for prec=53\n"); exit(1);
- }
+
+ mpfr_init (x);
+
+ check (2, 1000);
+
+ /* check precision of 2 bits */
+ mpfr_set_prec (x, 2);
+ mpfr_const_log2 (x, GMP_RNDN);
+ if (mpfr_get_d (x) != 0.75)
+ {
+ fprintf (stderr, "mpfr_const_log2 failed for prec=2, rnd=GMP_RNDN\n");
+ fprintf (stderr, "expected 0.75, got %f\n", mpfr_get_d (x));
+ exit (1);
+ }
+
+ if (argc>=2)
+ {
+ mpfr_set_prec (x, p);
+ mpfr_const_log2 (x, rnd);
+ printf ("log(2)=");
+ mpfr_out_str (stdout, 10, 0, x, rnd);
+ putchar('\n');
+ }
+
+ mpfr_set_prec (x, 53);
+ mpfr_const_log2 (x, rnd);
+ if (mpfr_get_d(x) != 6.9314718055994530941e-1)
+ {
+ fprintf (stderr, "mpfr_const_log2 failed for prec=53\n");
+ exit (1);
+ }
+
mpfr_clear(x);
return 0;