summaryrefslogtreecommitdiff
path: root/tests/tasin.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-01-22 22:30:52 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2004-01-22 22:30:52 +0000
commit031deac645662aea8a72a5ed0c0bf148e609e681 (patch)
tree07c68b885a0c39a228ca4b0f7f901a9117f85a9f /tests/tasin.c
parent039c1c0135bac8353d17020543fe8b27f3b1937e (diff)
downloadmpfr-031deac645662aea8a72a5ed0c0bf148e609e681.tar.gz
added several hard-coded tests (and fixed bugs found)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2644 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'tests/tasin.c')
-rw-r--r--tests/tasin.c136
1 files changed, 119 insertions, 17 deletions
diff --git a/tests/tasin.c b/tests/tasin.c
index 3f0b6cdbe..e3694d9c9 100644
--- a/tests/tasin.c
+++ b/tests/tasin.c
@@ -28,36 +28,138 @@ MA 02111-1307, USA. */
#define TEST_FUNCTION mpfr_asin
#include "tgeneric.c"
-int
-main (void)
+static void
+special (void)
{
- mpfr_t x, y, z;
-
- tests_start_mpfr ();
+ mpfr_t x, y;
+ mp_rnd_t r;
mpfr_init (x);
mpfr_init (y);
- mpfr_init (z);
- /* check that sin(-1) = -Pi/2 */
- mpfr_set_si (x, -1, GMP_RNDN);
+ /* asin(NaN) = NaN */
+ mpfr_set_nan (x);
mpfr_asin (y, x, GMP_RNDN);
- mpfr_const_pi (z, GMP_RNDN);
- mpfr_div_2exp (z, z, 1, GMP_RNDN);
- mpfr_neg (z, z, GMP_RNDN);
- if (mpfr_cmp (y, z))
+ if (!mpfr_nan_p (y))
{
- printf ("sin(-1) is wrong, expected -Pi/2, got ");
- mpfr_out_str(stdout, 10, 0, y, GMP_RNDN);
- putchar('\n');
+ printf ("Error: mpfr_asin (NaN) <> NaN\n");
exit (1);
}
- test_generic (2, 100, 7);
+ /* asin(+/-Inf) = NaN */
+ mpfr_set_inf (x, 1);
+ mpfr_asin (y, x, GMP_RNDN);
+ if (!mpfr_nan_p (y))
+ {
+ printf ("Error: mpfr_asin (+Inf) <> NaN\n");
+ exit (1);
+ }
+ mpfr_set_inf (x, -1);
+ mpfr_asin (y, x, GMP_RNDN);
+ if (!mpfr_nan_p (y))
+ {
+ printf ("Error: mpfr_asin (-Inf) <> NaN\n");
+ exit (1);
+ }
+
+ /* asin(+/-2) = NaN */
+ mpfr_set_ui (x, 2, GMP_RNDN);
+ mpfr_asin (y, x, GMP_RNDN);
+ if (!mpfr_nan_p (y))
+ {
+ printf ("Error: mpfr_asin (+2) <> NaN\n");
+ exit (1);
+ }
+ mpfr_set_si (x, -2, GMP_RNDN);
+ mpfr_asin (y, x, GMP_RNDN);
+ if (!mpfr_nan_p (y))
+ {
+ printf ("Error: mpfr_asin (-2) <> NaN\n");
+ exit (1);
+ }
+
+ /* asin(+/-0) = +/-0 */
+ mpfr_set_ui (x, 0, GMP_RNDN);
+ mpfr_asin (y, x, GMP_RNDN);
+ if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) < 0)
+ {
+ printf ("Error: mpfr_asin (+0) <> +0\n");
+ exit (1);
+ }
+ mpfr_neg (x, x, GMP_RNDN);
+ mpfr_asin (y, x, GMP_RNDN);
+ if (mpfr_cmp_ui (y, 0) || mpfr_sgn (y) > 0)
+ {
+ printf ("Error: mpfr_asin (-0) <> -0\n");
+ exit (1);
+ }
+
+ /* asin(1) = Pi/2 */
+ for (r = 0; r < 4; r++)
+ {
+ mpfr_set_ui (x, 1, GMP_RNDN); /* exact */
+ mpfr_asin (y, x, r);
+ mpfr_const_pi (x, r);
+ mpfr_div_2exp (x, x, 1, GMP_RNDN); /* exact */
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error: asin(1) != Pi/2 for rnd=%s\n",
+ mpfr_print_rnd_mode (r));
+ exit (1);
+ }
+ }
+
+ /* asin(-1) = -Pi/2 */
+ for (r = 0; r < 4; r++)
+ {
+ mpfr_set_si (x, -1, GMP_RNDN); /* exact */
+ mpfr_asin (y, x, r);
+ mpfr_const_pi (x, MPFR_INVERT_RND(r));
+ mpfr_neg (x, x, GMP_RNDN); /* exact */
+ mpfr_div_2exp (x, x, 1, GMP_RNDN); /* exact */
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error: asin(-1) != -Pi/2 for rnd=%s\n",
+ mpfr_print_rnd_mode (r));
+ exit (1);
+ }
+ }
+
+ mpfr_set_prec (x, 32);
+ mpfr_set_prec (y, 32);
+
+ mpfr_set_str_binary (x, "0.1101110111111111001011101000101");
+ mpfr_asin (x, x, GMP_RNDN);
+ mpfr_set_str_binary (y, "1.00001100101011000001111100111");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error: mpfr_asin (1)\n");
+ exit (1);
+ }
+
+ mpfr_set_str_binary (x, "-0.01110111000011101010111100000101");
+ mpfr_asin (x, x, GMP_RNDN);
+ mpfr_set_str_binary (y, "-0.0111101111010100011111110101");
+ if (mpfr_cmp (x, y))
+ {
+ printf ("Error: mpfr_asin (2)\n");
+ mpfr_print_binary (x); printf ("\n");
+ mpfr_print_binary (y); printf ("\n");
+ exit (1);
+ }
mpfr_clear (x);
mpfr_clear (y);
- mpfr_clear (z);
+}
+
+int
+main (void)
+{
+ tests_start_mpfr ();
+
+ special ();
+
+ test_generic (2, 100, 7);
tests_end_mpfr ();