summaryrefslogtreecommitdiff
path: root/tests/tget_set_d64.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-06-22 15:00:37 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2018-06-22 15:00:37 +0000
commit0fbd7688484d9b0f6fcd1423d8461f59f749e576 (patch)
tree3a8df6db4a93025309bbd6d96ac610b2421edec1 /tests/tget_set_d64.c
parentc02c7c24e78d920735369fe795f71ed99809d119 (diff)
downloadmpfr-0fbd7688484d9b0f6fcd1423d8461f59f749e576.tar.gz
[tests/tget_set_d64.c] test random inputs
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@12844 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tget_set_d64.c')
-rw-r--r--tests/tget_set_d64.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/tget_set_d64.c b/tests/tget_set_d64.c
index 5ee09901a..eb66ed943 100644
--- a/tests/tget_set_d64.c
+++ b/tests/tget_set_d64.c
@@ -505,6 +505,41 @@ coverage (void)
#endif
}
+/* generate random sequences of 8 bytes and interpret them as _Decimal64 */
+static void
+check_random_bytes (void)
+{
+ union {
+ _Decimal64 d;
+ unsigned char c[8];
+ } x;
+ int i;
+ mpfr_t y;
+ _Decimal64 e;
+
+ mpfr_init2 (y, 55); /* 55 = 1 + ceil(16*log(10)/log(2)), thus ensures
+ that if a decimal64 number is converted to a 55-bit
+ value and back, we should get the same value */
+ for (i = 0; i < 100000; i++)
+ {
+ int j;
+ for (j = 0; j < 8; j++)
+ x.c[j] = randlimb () & 255;
+ mpfr_set_decimal64 (y, x.d, MPFR_RNDN);
+ e = mpfr_get_decimal64 (y, MPFR_RNDN);
+ if (!mpfr_nan_p (y))
+ if (x.d != e)
+ {
+ printf ("check_random_bytes failed\n");
+ printf ("x.d="); print_decimal64 (x.d);
+ printf ("y="); mpfr_dump (y);
+ printf ("e="); print_decimal64 (e);
+ exit (1);
+ }
+ }
+ mpfr_clear (y);
+}
+
int
main (int argc, char *argv[])
{
@@ -520,6 +555,7 @@ main (int argc, char *argv[])
printf ("Using BID format\n");
#endif
+ check_random_bytes ();
coverage ();
check_misc ();
check_random ();