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

81 lines
1.7 KiB
C

/*
Copyright (C) 1995-2003, The AROS Development Team. All rights reserved.
*/
#include "mathtrans_intern.h"
/*****************************************************************************
NAME */
AROS_LH1(float, SPCosh,
/* SYNOPSIS */
AROS_LHA(float, fnum1, D0),
/* LOCATION */
struct Library *, MathTransBase, 11, MathTrans)
/* FUNCTION
Calculate the hyperbolic cosine of the ffp number
INPUTS
RESULT
Motorola fast floating point number
flags:
zero : result is zero
negative : 0 (not possible)
overflow : result too big for ffp-number
BUGS
INTERNALS
cosh(x) = (1/2)*( e^x + e^(-x) )
cosh( |x| >= 44 ) = infinity;
cosh( |x| >= 9 ) = (1/2) * (e^x);
*****************************************************************************/
{
AROS_LIBFUNC_INIT
ULONG Res;
LONG tmp;
/* cosh(-x) = cosh(x) */
fnum1 &= ( FFPMantisse_Mask + FFPExponent_Mask );
Res = SPExp(fnum1);
if ( FFP_Pinfty == Res )
{
SetSR(Overflow_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
return Res;
}
tmp = (fnum1 & FFPExponent_Mask) - 0x41;
if ( tmp <= 2 || (tmp == 3 && (fnum1 & FFPMantisse_Mask) < 0x90000000) )
{
Res = SPAdd(Res, SPDiv(Res, one));
}
/* Res = Res / 2 */
/* should be ((char)Res) --, but gcc on Linux screws up the result */
tmp = Res & 0xFFFFFF00;
Res -= sizeof(char);
Res = tmp | Res;
if (0 == Res || (char)Res < 0 )
{
SetSR(Zero_Bit, Zero_Bit | Negative_Bit | Overflow_Bit);
return 0;
}
return Res;
AROS_LIBFUNC_EXIT
}