diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-02-01 08:07:19 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-02-01 08:07:19 +0000 |
commit | f256728c5880c108bb64e81aefed02ea9b2ed7e0 (patch) | |
tree | 2c3fd5cc7ea4b63ce5afe52298a0ee6fd7fb9f77 /src/asinu.c | |
parent | 7fc0b0d10f9b2f30b14ed77e3b76d4da87a957f2 (diff) | |
download | mpfr-f256728c5880c108bb64e81aefed02ea9b2ed7e0.tar.gz |
[src/asinu.c] return NaN for u=0 and |x| > 1
[tests/tasinu.c] added more tests
git-svn-id: https://scm.gforge.inria.fr/anonscm/svn/mpfr/trunk@14294 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/asinu.c')
-rw-r--r-- | src/asinu.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/asinu.c b/src/asinu.c index f87e83de3..db6120967 100644 --- a/src/asinu.c +++ b/src/asinu.c @@ -59,31 +59,37 @@ mpfr_asinu (mpfr_ptr y, mpfr_srcptr x, unsigned long u, mpfr_rnd_t rnd_mode) } compared = mpfr_cmpabs_ui (x, 1); - if (compared >= 0) + if (compared > 0) { - /* asinu(x) = NaN for |x| > 1 */ - if (compared > 0) - { - MPFR_SET_NAN (y); - MPFR_RET_NAN; - } - else /* |x| = 1: asinu(1,u) = u/4, asinu(-1,u)=-u/4 */ + /* asinu(x) = NaN for |x| > 1, included for u=0, since NaN*0 = NaN */ + MPFR_SET_NAN (y); + MPFR_RET_NAN; + } + + if (u == 0) /* return 0 with sign of x */ + { + MPFR_SET_ZERO (y); + MPFR_SET_POS (y); + MPFR_RET (0); + } + + if (compared == 0) + { + /* |x| = 1: asinu(1,u) = u/4, asinu(-1,u)=-u/4 */ + /* we can't use mpfr_set_si_2exp with -u since -u might not be + representable as long */ + if (MPFR_SIGN(x) > 0) + return mpfr_set_ui_2exp (y, u, -2, rnd_mode); + else { - /* we can't use mpfr_set_si_2exp with -u since -u might not be - representable as long */ - if (MPFR_SIGN(x) > 0) - return mpfr_set_ui_2exp (y, u, -2, rnd_mode); - else - { - inexact = mpfr_set_ui_2exp (y, u, -2, MPFR_INVERT_RND(rnd_mode)); - MPFR_CHANGE_SIGN(y); - return -inexact; - } + inexact = mpfr_set_ui_2exp (y, u, -2, MPFR_INVERT_RND(rnd_mode)); + MPFR_CHANGE_SIGN(y); + return -inexact; } } - /* asin(+/-1/2) = +/-pi/6, thus in this case asin(x,u) is exact when - u is a multiple of 3 */ + /* asin(+/-1/2) = +/-pi/6, thus asin(+/-1/2,u) = +/-u/12 is exact when u is + a multiple of 3 */ if (mpfr_cmp_si_2exp (x, MPFR_SIGN(x), -1) == 0 && (u % 3) == 0) { long v = u / 3; |