diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2000-06-07 09:45:23 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2000-06-07 09:45:23 +0000 |
commit | 20f1ad61b1233df8b9e0bd7c3542d8e4c1d68ecf (patch) | |
tree | c40ec10c974fab69f6ddfefa8f1aef3774a655a2 /tests/texp2.c | |
parent | 36243651f4b25cb1bda392c22a5a7f6abcb64c52 (diff) | |
download | mpfr-20f1ad61b1233df8b9e0bd7c3542d8e4c1d68ecf.tar.gz |
test file comparing mpfr_exp and mpfr_exp2
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@603 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/texp2.c')
-rw-r--r-- | tests/texp2.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/texp2.c b/tests/texp2.c new file mode 100644 index 000000000..bcad3cdfb --- /dev/null +++ b/tests/texp2.c @@ -0,0 +1,48 @@ +#include <math.h> +#include <stdlib.h> +#include <unistd.h> +#include "gmp.h" +#include "gmp-impl.h" +#include "mpfr.h" +#include "cputime.h" + +extern int mpfr_exp2 (mpfr_ptr, mpfr_srcptr, mp_rnd_t); + +int main(int argc,char *argv[]) +{ + mpfr_t x, y, z; int prec, rnd, N, i, st; + + srand(getpid()); + if (argc!=4) { + fprintf(stderr,"Usage: texp2 prec rnd N\n"); exit(1); + } + prec = atoi(argv[1]); + rnd = atoi(argv[2]); + N = atoi(argv[3]); + mpfr_init2(x, prec); mpfr_random(x); + /* printf("x="); mpfr_print_raw(x); putchar('\n'); */ + mpfr_init2(y, prec); + mpfr_init2(z, prec); + + mpfr_exp2(z, x, rnd); /* log(2) initialization */ + + st=cputime(); + for (i=0; i<N; i++) mpfr_exp2(z, x, rnd); + printf("mpfr_exp2 takes %dms\n", cputime()-st); + + mpfr_exp(y, x, rnd); /* log(2) initialization */ + + st=cputime(); + for (i=0; i<N; i++) mpfr_exp(y, x, rnd); + printf("mpfr_exp takes %dms\n", cputime()-st); + + if (mpfr_cmp(y,z)) { + printf("mpfr_exp and mpfr_exp2 disagree for\nx="); + mpfr_print_raw(x); putchar('\n'); + printf("mpfr_exp gives "); mpfr_print_raw(y); putchar('\n'); + printf("mpfr_exp2 gives "); mpfr_print_raw(z); putchar('\n'); + } + return 0; +} + + |