diff options
author | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-03-09 17:31:29 +0000 |
---|---|---|
committer | pelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-03-09 17:31:29 +0000 |
commit | 816bba8ca03279e1c1113bb9eab7bdc28cdd4470 (patch) | |
tree | 0a7fd0a3ee44cf1ed673f1392cbf2dc6577bb279 /tests/tset_si.c | |
parent | 4b4042b221bed3d420dbbc5f100ce21084d6fbfa (diff) | |
download | mpfr-816bba8ca03279e1c1113bb9eab7bdc28cdd4470.tar.gz |
Add mpfr_set_si_2exp and mpfr_set_ui_2exp and their tests.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2829 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tset_si.c')
-rw-r--r-- | tests/tset_si.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/tset_si.c b/tests/tset_si.c index 26c848993..6e535470d 100644 --- a/tests/tset_si.c +++ b/tests/tset_si.c @@ -22,9 +22,45 @@ MA 02111-1307, USA. */ #include <stdio.h> #include <stdlib.h> #include <time.h> +#include <limits.h> #include "mpfr-test.h" +#define ERROR(str) {printf("Error for "str); exit(1);} + +static void +test_2exp (void) +{ + mpfr_t x; + + mpfr_init2 (x, 32); + + mpfr_set_ui_2exp (x, 1, 0, GMP_RNDN); + if (mpfr_cmp_ui(x, 1)) + ERROR("(1U,0)"); + + mpfr_set_ui_2exp (x, 1024, -10, GMP_RNDN); + if (mpfr_cmp_ui(x, 1)) + ERROR("(1024U,-10)"); + + mpfr_set_ui_2exp (x, 1024, 10, GMP_RNDN); + if (mpfr_cmp_ui(x, 1024*1024)) + ERROR("(1024U,+10)"); + + mpfr_set_si_2exp (x, -1024*1024, -10, GMP_RNDN); + if (mpfr_cmp_si(x, -1024)) + ERROR("(1M,-10)"); + + mpfr_set_ui_2exp (x, 0x92345678, 16, GMP_RNDN); + if (mpfr_cmp_str (x, "92345678@4", 16, GMP_RNDN)) + ERROR("(x92345678U,+16)"); + + mpfr_set_si_2exp (x, -0x1ABCDEF0, -256, GMP_RNDN); + if (mpfr_cmp_str (x, "-1ABCDEF0@-64", 16, GMP_RNDN)) + ERROR("(-x1ABCDEF0,-256)"); + + mpfr_clear (x); +} /* FIXME: Comparing against mpfr_get_si/ui is not ideal, it'd be better to have all tests examine the bits in mpfr_t for what should come out. */ @@ -199,6 +235,7 @@ main (int argc, char *argv[]) mpfr_clear (x); + test_2exp (); tests_end_mpfr (); return 0; } |