summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/tcosu.c53
-rw-r--r--tests/tsinu.c37
-rw-r--r--tests/ttanu.c37
3 files changed, 127 insertions, 0 deletions
diff --git a/tests/tcosu.c b/tests/tcosu.c
index 2f492c859..bb3538dc2 100644
--- a/tests/tcosu.c
+++ b/tests/tcosu.c
@@ -166,6 +166,58 @@ test_regular (void)
mpfr_clear (z);
}
+/* Check argument reduction with large hard-coded inputs. The following values were
+ generated with the following Sage code:
+# generate N random tests for f, with precision p, u < U, and |x| < 2^K
+# f might be cos (for cosu), sin (for sinu) or tan (for tanu)
+# gen_random(cos,10,53,100,20)
+def gen_random(f,N,p,U,K):
+ R = RealField(p)
+ for n in range(N):
+ u = ZZ.random_element(U)
+ x = R.random_element()*2^K
+ q = p
+ while true:
+ q += 10
+ RI = RealIntervalField(q)
+ y = RI(f(2*pi*x.exact_rational()/u))
+ if R(y.lower().exact_rational()) == R(y.upper().exact_rational()):
+ break
+ y = R(y.lower().exact_rational())
+ print (x.hex(), u, y.hex()) */
+static void
+test_large (void)
+{
+#define SIZE 10
+ static double T[SIZE][3] = {
+ {0xd.ddfeb0f4a01fp+16, 72, 0x4.8e54ce9b84d78p-4},
+ {-0xb.ccb63f74f9abp+16, 36, -0xb.cce98d64941bp-4},
+ {0x9.8451e45ed4bap+16, 26, -0xb.b205cfe8a13cp-4},
+ {-0x7.6b4c16c45445p+16, 60, -0x7.dee04000f4934p-4},
+ {0x1.bb80916be884p+16, 43, -0xc.059d9c8f1b7fp-4},
+ {-0x5.4d3623b69226p+16, 1, 0xa.3cb353892757p-4},
+ {0xd.1c59eab5a14bp+16, 58, 0x1.02978f1c99614p-4},
+ {-0xf.bb1f858b9949p+16, 33, -0x3.b53e5214db138p-4},
+ {-0x2.9bcda761bb7p+16, 55, -0x6.e6c08e7d92898p-4},
+ {-0x9.f8f40e2c50f9p+16, 73, 0x7.0e0ff5e4dccbp-4}
+ };
+ int i;
+ unsigned long u;
+
+ mpfr_t x, y, z;
+ mpfr_inits2 (53, x, y, z, (mpfr_ptr) NULL);
+ for (i = 0; i < SIZE; i++)
+ {
+ mpfr_set_d (x, T[i][0], MPFR_RNDN);
+ u = (unsigned long) T[i][1];
+ mpfr_set_d (y, T[i][2], MPFR_RNDN);
+ mpfr_cosu (z, x, u, MPFR_RNDN);
+ MPFR_ASSERTN (mpfr_equal_p (y, z));
+ }
+ mpfr_clears (x, y, z, (mpfr_ptr) NULL);
+#undef SIZE
+}
+
/* FIXME[VL]: For mpfr_cosu, the range reduction should not be expensive.
If I'm not mistaken, this is linear in the bitsize of the exponent
since one just needs to compute the argument modulo the integer u. */
@@ -192,6 +244,7 @@ main (void)
test_singular ();
test_exact ();
test_regular ();
+ test_large ();
/* Note: since the value of u can be large (up to 2^64 - 1 on 64-bit
machines), the cos argument can be very small, yielding a special
diff --git a/tests/tsinu.c b/tests/tsinu.c
index d8d962afd..43ffb27a8 100644
--- a/tests/tsinu.c
+++ b/tests/tsinu.c
@@ -166,6 +166,42 @@ test_regular (void)
mpfr_clear (z);
}
+/* Check argument reduction with large hard-coded inputs. The following values were
+ generated with gen_random(sin,10,53,100,20), where the Sage code for gen_random
+ is given in the tcosu.c file */
+static void
+test_large (void)
+{
+#define SIZE 10
+ static double T[SIZE][3] = {
+ {-0x4.338bcaf01cb4p+16, 37, 0xa.a85c8758c1228p-4},
+ {-0x6.01aa844d11acp+16, 12, 0x4.46e2cea96ee2cp-4},
+ {-0x7.997759de3b3dp+16, 35, 0xf.144b13bc0b008p-4},
+ {-0xc.74f72253bc7ep+16, 74, -0x9.1c24e8ac6fb48p-4},
+ {-0x4.ea97564d3ecp+12, 93, 0x3.2d49033cc4556p-4},
+ {0xc.1cd85e0766ffp+16, 48, -0xd.74b642b1c7368p-4},
+ {0xe.add2f0441bap+16, 82, -0xf.fc35c5a5e1448p-4},
+ {0xc.8feb943a0fe5p+16, 43, -0x5.8af3e0e11b794p-4},
+ {-0xd.d61b06ace6d9p+16, 55, 0xa.175c9f7e4ede8p-4},
+ {0xb.cf036b4e5fap+12, 46, 0x1.b7128e1975d9ap-4}
+ };
+ int i;
+ unsigned long u;
+
+ mpfr_t x, y, z;
+ mpfr_inits2 (53, x, y, z, (mpfr_ptr) NULL);
+ for (i = 0; i < SIZE; i++)
+ {
+ mpfr_set_d (x, T[i][0], MPFR_RNDN);
+ u = (unsigned long) T[i][1];
+ mpfr_set_d (y, T[i][2], MPFR_RNDN);
+ mpfr_sinu (z, x, u, MPFR_RNDN);
+ MPFR_ASSERTN (mpfr_equal_p (y, z));
+ }
+ mpfr_clears (x, y, z, (mpfr_ptr) NULL);
+#undef SIZE
+}
+
/* FIXME[VL]: For mpfr_sinu, the range reduction should not be expensive.
If I'm not mistaken, this is linear in the bitsize of the exponent
since one just needs to compute the argument modulo the integer u. */
@@ -192,6 +228,7 @@ main (void)
test_singular ();
test_exact ();
test_regular ();
+ test_large ();
test_generic (MPFR_PREC_MIN, 100, 1);
diff --git a/tests/ttanu.c b/tests/ttanu.c
index cf531af1a..8e55c26d5 100644
--- a/tests/ttanu.c
+++ b/tests/ttanu.c
@@ -190,6 +190,42 @@ test_regular (void)
mpfr_clear (z);
}
+/* Check argument reduction with large hard-coded inputs. The following values were
+ generated with gen_random(tan,10,53,100,20), where the Sage code for gen_random
+ is given in the tcosu.c file */
+static void
+test_large (void)
+{
+#define SIZE 10
+ static double T[SIZE][3] = {
+ {-0x1.8f7cb49edc03p+16, 28, 0x4.c869fd8050554p-4},
+ {-0xe.8ede30716292p+16, 17, -0x2.c83df69d8fdecp+4},
+ {-0x8.f14a73a7b4a3p+16, 4, -0xd.be24a6d0fde98p-4},
+ {0xe.f82c4537b473p+16, 93, -0x5.d0d95fdc8ffbcp+0},
+ {0x8.4148f00c8418p+16, 50, 0x1.e4e4aa652b2a4p-4},
+ {-0x6.e8b69db10e63p+16, 27, -0x2.4f32f1977b7b2p-4},
+ {-0xe.a3ebf225ea2fp+16, 18, 0x6.5f7637f74517p+0},
+ {-0x5.580eb29168d8p+16, 92, 0x8.96418eed84e8p+0},
+ {0x8.13c5a1b43231p+16, 19, 0xb.2718b861b29fp-8},
+ {0x4.eb4e546e042dp+16, 64, 0x6.0b3ba821e4ep+0}
+ };
+ int i;
+ unsigned long u;
+
+ mpfr_t x, y, z;
+ mpfr_inits2 (53, x, y, z, (mpfr_ptr) NULL);
+ for (i = 0; i < SIZE; i++)
+ {
+ mpfr_set_d (x, T[i][0], MPFR_RNDN);
+ u = (unsigned long) T[i][1];
+ mpfr_set_d (y, T[i][2], MPFR_RNDN);
+ mpfr_tanu (z, x, u, MPFR_RNDN);
+ MPFR_ASSERTN (mpfr_equal_p (y, z));
+ }
+ mpfr_clears (x, y, z, (mpfr_ptr) NULL);
+#undef SIZE
+}
+
/* FIXME[VL]: For mpfr_tanu, the range reduction should not be expensive.
If I'm not mistaken, this is linear in the bitsize of the exponent
since one just needs to compute the argument modulo the integer u. */
@@ -216,6 +252,7 @@ main (void)
test_singular ();
test_exact ();
test_regular ();
+ test_large ();
test_generic (MPFR_PREC_MIN, 100, 1);