1
0
mirror of https://github.com/deadw00d/AROS.git synced 2025-12-06 21:40:57 +00:00
Files
AROS-v0/workbench/libs/mathtrans/sptanh.c
Matthias Rustler 6b5a534ce3 workbench: detabbed
2021-05-02 13:55:14 +02:00

85 lines
1.8 KiB
C

/*
Copyright (C) 1995-2003, The AROS Development Team. All rights reserved.
*/
#include "mathtrans_intern.h"
/*****************************************************************************
NAME */
AROS_LH1(float, SPTanh,
/* SYNOPSIS */
AROS_LHA(float, fnum1, D0),
/* LOCATION */
struct Library *, MathTransBase, 12, MathTrans)
/* FUNCTION
Calculate hyperbolic tangens of the ffp number
INPUTS
RESULT
Motorola fast floating point number
flags:
zero : result is zero
negative : result is negative
overflow : (not possible)
BUGS
INTERNALS
( e^x - e^(-x) )
tanh(x) = ----------------
( e^x + e^(-x) )
tanh( |x| > 9 ) = 1
*****************************************************************************/
{
AROS_LIBFUNC_INIT
ULONG Res;
LONG tmp;
tmp = (fnum1 & FFPExponent_Mask) - 0x41;
if ( tmp >= 3 && (fnum1 & FFPMantisse_Mask) >= 0x90000000 )
{
/*
tanh( x > 9 ) = 1
tanh( x <-9 ) = -1
*/
return (one | ( fnum1 & FFPSign_Mask ));
}
/* tanh(-x) = -tanh(x) */
Res = SPExp(fnum1 & (FFPMantisse_Mask + FFPExponent_Mask ));
Res = SPDiv
(
SPAdd(Res, SPDiv(Res, one)),
SPAdd(Res, (ULONG)SPDiv(Res, one) | FFPSign_Mask )
);
/* Result is zero */
if (0 == Res )
{
SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
return 0;
}
/* Argument is negative -> result is negative */
if ( (char) fnum1 < 0)
{
SetSR(Negative_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
return (Res | FFPSign_Mask );
}
return Res;
AROS_LIBFUNC_EXIT
}