[Gmp-commit] /var/hg/gmp: 2 new changesets
mercurial at gmplib.org
mercurial at gmplib.org
Sat Mar 18 00:53:25 UTC 2017
details: /var/hg/gmp/rev/6a6774ee8e2c
changeset: 17334:6a6774ee8e2c
user: Torbjorn Granlund <tg at gmplib.org>
date: Sun Mar 12 14:43:28 2017 +0100
description:
(check_data): Rewrite of check_onebit.
details: /var/hg/gmp/rev/bd5e734dcb13
changeset: 17335:bd5e734dcb13
user: Torbjorn Granlund <tg at gmplib.org>
date: Sun Mar 12 14:49:01 2017 +0100
description:
Amend last change: Let mpn_get_d handle sign.
diffstat:
mpf/get_d_2exp.c | 5 +---
tests/mpf/t-get_d_2exp.c | 64 ++++++++++++++++++++++++++---------------------
2 files changed, 36 insertions(+), 33 deletions(-)
diffs (114 lines):
diff -r 25df7ac80c25 -r bd5e734dcb13 mpf/get_d_2exp.c
--- a/mpf/get_d_2exp.c Sat Mar 11 10:58:11 2017 +0100
+++ b/mpf/get_d_2exp.c Sun Mar 12 14:49:01 2017 +0100
@@ -38,7 +38,6 @@
mp_size_t size, abs_size;
mp_srcptr ptr;
int cnt;
- double d;
size = SIZ(src);
if (UNLIKELY (size == 0))
@@ -53,7 +52,5 @@
cnt -= GMP_NAIL_BITS;
*expptr = EXP(src) * GMP_NUMB_BITS - cnt;
-
- d = mpn_get_d (ptr, abs_size, 0, -(abs_size * GMP_NUMB_BITS - cnt));
- return size >= 0 ? d : -d;
+ return mpn_get_d (ptr, abs_size, size, -(abs_size * GMP_NUMB_BITS - cnt));
}
diff -r 25df7ac80c25 -r bd5e734dcb13 tests/mpf/t-get_d_2exp.c
--- a/tests/mpf/t-get_d_2exp.c Sat Mar 11 10:58:11 2017 +0100
+++ b/tests/mpf/t-get_d_2exp.c Sun Mar 12 14:49:01 2017 +0100
@@ -1,6 +1,6 @@
/* Test mpf_get_d_2exp.
-Copyright 2002, 2003 Free Software Foundation, Inc.
+Copyright 2002, 2003, 2017 Free Software Foundation, Inc.
This file is part of the GNU MP Library test suite.
@@ -24,40 +24,46 @@
static void
-check_onebit (void)
+check_data (void)
{
- static const long data[] = {
- -513, -512, -511, -65, -64, -63, -32, -1,
- 0, 1, 32, 53, 54, 64, 128, 256, 511, 512, 513
- };
mpf_t f;
double got, want;
- long got_exp, want_exp;
- int i;
+ long got_exp;
+ long exp;
+ struct {
+ int base;
+ int shift;
+ } data[] = {
+ {-1, 1}, {-3, 2}, {-5, 3}, {-7, 3}, { 1, 1}, { 3, 2}, { 5, 3}, { 7, 3}
+ };
- mpf_init2 (f, 1024L);
+ mpf_init2 (f, 3);
- for (i = 0; i < numberof (data); i++)
+ for (exp = -513; exp <= 513; exp++)
{
- mpf_set_ui (f, 1L);
- if (data[i] >= 0)
- mpf_mul_2exp (f, f, data[i]);
- else
- mpf_div_2exp (f, f, -data[i]);
- want = 0.5;
- want_exp = data[i] + 1;
+ size_t i;
+ for (i = 0; i < numberof (data); i++)
+ {
+ want = (double) data[i].base / (1 << data[i].shift);
+ mpf_set_d (f, want);
- got = mpf_get_d_2exp (&got_exp, f);
- if (got != want || got_exp != want_exp)
- {
- printf ("mpf_get_d_2exp wrong on 2**%ld\n", data[i]);
- mpf_trace (" f ", f);
- d_trace (" want ", want);
- d_trace (" got ", got);
- printf (" want exp %ld\n", want_exp);
- printf (" got exp %ld\n", got_exp);
- abort();
- }
+ if (exp >= 0)
+ mpf_mul_2exp (f, f, exp);
+ else
+ mpf_div_2exp (f, f, -exp);
+
+ got = mpf_get_d_2exp (&got_exp, f);
+ if (got != want || got_exp != exp)
+ {
+ printf ("mpf_get_d_2exp wrong on 2**%ld\n", exp);
+ mpf_trace (" f ", f);
+ d_trace (" want ", want);
+ d_trace (" got ", got);
+ printf (" want exp %ld\n", exp);
+ printf (" got exp %ld\n", got_exp);
+ abort();
+ }
+ }
}
mpf_clear (f);
}
@@ -112,7 +118,7 @@
tests_start ();
mp_trace_base = 16;
- check_onebit ();
+ check_data ();
check_round ();
tests_end ();
More information about the gmp-commit
mailing list