diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2005-02-18 15:28:25 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2005-02-18 15:28:25 +0000 |
commit | dbae7636bce46ccab71535d8fa45529332694001 (patch) | |
tree | deee5fbab4774018ad86ad55abda8eba06cc12b9 /tests/RRTest.c | |
parent | 61c92b49bb78f3c859e4e14e53ebbbfaa1892334 (diff) | |
download | mpfr-dbae7636bce46ccab71535d8fa45529332694001.tar.gz |
added interface for NTL
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@3335 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/RRTest.c')
-rw-r--r-- | tests/RRTest.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/RRTest.c b/tests/RRTest.c new file mode 100644 index 000000000..ad519e783 --- /dev/null +++ b/tests/RRTest.c @@ -0,0 +1,84 @@ +/* Example file to test mpfr addition against NTL. + Usage: + 0) compile this file with NTL + 1) compile tadd.c with -DCHECK_EXTERNAL + 2) ./tadd | egrep -v 'Seed|Inf|NaN' > /tmp/add.log + (Warning, this produces a large file.) + 3) ./RRTest < /tmp/add.log +*/ + +#include <NTL/mat_RR.h> + +NTL_CLIENT + +void +ReadBinary (ZZ &x) +{ + int s = 1; + ZZ b, y; + + cin >> b; + + if (b < 0) + { + s = -1; + b = -b; + } + + x = 0; + y = 1; + while (b != 0) + { + x += (b % 10) * y; + y *= 2; + b /= 10; + } + if (s < 0) + x = -x; +} + +long +ReadRR (RR &a) +{ + long p; + ZZ x; + long e; + + cin >> p; + ReadBinary (x); + cin >> e; + MakeRRPrec (a, x, e, p); + return p; +} + +void +Output (RR a) +{ + cout << a.mantissa() << "*2^(" << a.exponent() << ")" << endl; +} + +int main() +{ + RR a, b, c, d; + long line = 0; + long p; + + while (!feof(stdin)) + { + if (++line % 1000 == 0) + cout << "line " << line << endl; + ReadRR (b); + ReadRR (c); + p = ReadRR (a); + AddPrec (d, b, c, p); + if (d != a) + { + cerr << "error at line " << line << " for b="; Output(b); + cerr << " c="; Output(c); + cerr << "expected "; Output(a); + cerr << "got "; Output(d); + cerr << "prec(d)=" << d.precision() << endl; + exit (1); + } + } +} |