summaryrefslogtreecommitdiff
path: root/acos.c
diff options
context:
space:
mode:
authorpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-28 16:31:13 +0000
committerpelissip <pelissip@280ebfd0-de03-0410-8827-d642c229c3f4>2003-10-28 16:31:13 +0000
commit117edf14c822a22cdd9c25689aeadc904a1a30d1 (patch)
treee39bd61cefc24cc6cfbc5b2b956e4fb36015d111 /acos.c
parent734c0a144b04e2cae4e67b394010e3f6e3cadecc (diff)
downloadmpfr-117edf14c822a22cdd9c25689aeadc904a1a30d1.tar.gz
Use of MPFR_UNLIKELY and MPFR_IS_SINGULAR for fast detection of special values (Nan, Inf or Zero).
Start to encapsulate the sign to be independant of the reprensation (Must be 1 or -1). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2525 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'acos.c')
-rw-r--r--acos.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/acos.c b/acos.c
index 093734b65..74b95af54 100644
--- a/acos.c
+++ b/acos.c
@@ -40,11 +40,22 @@ mpfr_acos (mpfr_ptr acos, mpfr_srcptr x, mp_rnd_t rnd_mode)
int compared;
int inexact = 0;
- /* Trivial cases */
- if (MPFR_IS_NAN(x) || MPFR_IS_INF(x))
+ /* Special cases */
+ if (MPFR_UNLIKELY( MPFR_IS_SINGULAR(x) ))
{
- MPFR_SET_NAN(acos);
- MPFR_RET_NAN;
+ if (MPFR_IS_NAN(x) || MPFR_IS_INF(x))
+ {
+ MPFR_SET_NAN(acos);
+ MPFR_RET_NAN;
+ }
+ else if (MPFR_IS_ZERO(x))
+ {
+ /* acos(0)=Pi/2 */
+ mpfr_const_pi (acos, rnd_mode);
+ MPFR_SET_EXP (acos, MPFR_GET_EXP (acos) - 1);
+ return 1; /* inexact */
+ }
+ MPFR_ASSERTN(1);
}
/* Set x_p=|x| */
@@ -64,7 +75,7 @@ mpfr_acos (mpfr_ptr acos, mpfr_srcptr x, mp_rnd_t rnd_mode)
if (compared == 0)
{
mpfr_clear (xp);
- if (signe > 0) /* acos(+1) = 0 */
+ if (MPFR_IS_POS_SIGN(signe)) /* acos(+1) = 0 */
return mpfr_set_ui (acos, 0, rnd_mode);
else /* acos(-1) = Pi */
{
@@ -73,18 +84,10 @@ mpfr_acos (mpfr_ptr acos, mpfr_srcptr x, mp_rnd_t rnd_mode)
}
}
- if (MPFR_IS_ZERO(x)) /* acos(0)=Pi/2 */
- {
- mpfr_clear (xp);
- mpfr_const_pi (acos, rnd_mode);
- MPFR_SET_EXP (acos, MPFR_GET_EXP (acos) - 1);
- return 1; /* inexact */
- }
-
prec_acos = MPFR_PREC(acos);
mpfr_ui_sub (xp, 1, xp, GMP_RNDD);
- if (signe > 0)
+ if (MPFR_IS_POS_SIGN(signe))
supplement = 2 - 2 * MPFR_GET_EXP (xp);
else
supplement = 2 - MPFR_GET_EXP(xp);