Underflow in ctanh()

Damian McGuckin damianm@esi.com.au
Thu Jul 3 01:56:23 GMT 2025


On Wed, 2 Jul 2025, Damian McGuckin wrote:

> Rather than compensating for overflow, why not just compute
>
> 	FLOAT exp_neg_x = M_EXP(-M_FABS(__real__ x))
>
> This is either normal with no exception, or subnormal or zero with an 
> underflow exception.  If exp(-|x|) was so small as to raise an exception,
> this is desired.
>
> Subsequently, then compute
>
> 	__imag__ res = ((4 * sinix * cosix) * exp_neg_x) * exp_neg_x;
>
> If s is normal but tiny, that last expression might correctly underflow
> which is what is desired.

To answer my own question, the current method is slightly more accurate.
Whether it is worth the extra logic is another question for another time

Thanks - Damian


More information about the Libc-alpha mailing list