summaryrefslogtreecommitdiff
path: root/tanh.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 /tanh.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 'tanh.c')
-rw-r--r--tanh.c53
1 files changed, 23 insertions, 30 deletions
diff --git a/tanh.c b/tanh.c
index 885419bce..0d93596bd 100644
--- a/tanh.c
+++ b/tanh.c
@@ -30,14 +30,7 @@ MA 02111-1307, USA. */
*/
int
-#if __STDC__
mpfr_tanh (mpfr_ptr y, mpfr_srcptr xt , mp_rnd_t rnd_mode)
-#else
-mpfr_tanh (y, xt, rnd_mode)
- mpfr_ptr y;
- mpfr_srcptr xt;
- mp_rnd_t rnd_mode;
-#endif
{
/****** Declaration ******/
@@ -46,35 +39,35 @@ mpfr_tanh (y, xt, rnd_mode)
int flag_neg=0, inexact=0;
/* Special value checking */
-
- if (MPFR_IS_NAN(xt))
+ if (MPFR_UNLIKELY(MPFR_IS_SINGULAR(xt)))
{
- MPFR_SET_NAN(y);
- MPFR_RET_NAN;
- }
- MPFR_CLEAR_NAN(y);
-
- if (MPFR_IS_INF(xt))
- {
- if (MPFR_SIGN(xt) > 0)
- return mpfr_set_si(y,1,rnd_mode); /* tanh(inf) = 1 */
- else
- return mpfr_set_si(y,-1,rnd_mode); /* tanh(-inf) = -1 */
- }
- MPFR_CLEAR_INF(y);
-
- /* tanh(0) = 0 */
- if (MPFR_IS_ZERO(xt))
- {
- MPFR_SET_ZERO(y);
- MPFR_SET_SAME_SIGN(y,xt);
- MPFR_RET(0);
+ if (MPFR_IS_NAN(xt))
+ {
+ MPFR_SET_NAN(y);
+ MPFR_RET_NAN;
+ }
+ else if (MPFR_IS_INF(xt))
+ {
+ if (MPFR_IS_POS(xt))
+ return mpfr_set_si(y,1,rnd_mode); /* tanh(inf) = 1 */
+ else
+ return mpfr_set_si(y,-1,rnd_mode); /* tanh(-inf) = -1 */
+ }
+ /* tanh(0) = 0 */
+ else if (MPFR_IS_ZERO(xt))
+ {
+ MPFR_SET_ZERO(y);
+ MPFR_SET_SAME_SIGN(y,xt);
+ MPFR_RET(0);
+ }
+ /* Should never reach this point */
+ MPFR_ASSERTN(1);
}
mpfr_init2(x,Nxt);
mpfr_set(x,xt,GMP_RNDN);
- if (MPFR_SIGN(x) < 0)
+ if (MPFR_IS_NEG(x))
{
MPFR_CHANGE_SIGN(x);
flag_neg=1;