* [musl] Special cases in csinh and ctanh @ 2024-08-06 14:02 Damian McGuckin 2024-08-06 15:46 ` Markus Wichmann 0 siblings, 1 reply; 3+ messages in thread From: Damian McGuckin @ 2024-08-06 14:02 UTC (permalink / raw) To: MUSL Some special cases in ctanh.c are listed below: /* * ctanh(+-0 + i NAN) = +-0 + i NaN * ctanh(+-0 +- i Inf) = +-0 + i NaN * ctanh(x + i NAN) = NaN + i NaN * ctanh(x +- i Inf) = NaN + i NaN */ if (!isfinite(y)) return CMPLX(x ? y - y : x, y - y); What I thought are the same special cases in csinh.c are listed below: They are processed differently in csinh than in ctanh. /* * sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN. * The sign of 0 in the result is unspecified. Choice = normally * the same as dNaN. Raise the invalid floating-point exception. * * sinh(+-0 +- I NaN) = sign(d(+-0, NaN))0 + I d(NaN). * The sign of 0 in the result is unspecified. Choice = normally * the same as d(NaN). */ if ((ix | lx) == 0 && iy >= 0x7ff00000) return CMPLX(copysign(0, x * (y - y)), y - y); /* * sinh(x +- I Inf) = dNaN + I dNaN. * Raise the invalid floating-point exception for finite nonzero x. * * sinh(x + I NaN) = d(NaN) + I d(NaN). * Optionally raises the invalid floating-point exception for finite * nonzero x. Choice = don't raise (except for signaling NaNs). */ if (ix < 0x7ff00000 && iy >= 0x7ff00000) return CMPLX(y - y, x * (y - y)); I realise that 'y - y' creates a NaN when y is either an Infinity or NaN. Won't that also raise an INVALID exception? What does x * (y - y) achieve that y - y does not (in the above) Thanks - Damian ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [musl] Special cases in csinh and ctanh 2024-08-06 14:02 [musl] Special cases in csinh and ctanh Damian McGuckin @ 2024-08-06 15:46 ` Markus Wichmann 2024-08-07 0:51 ` Damian McGuckin 0 siblings, 1 reply; 3+ messages in thread From: Markus Wichmann @ 2024-08-06 15:46 UTC (permalink / raw) To: musl; +Cc: Damian McGuckin Am Wed, Aug 07, 2024 at 12:02:59AM +1000 schrieb Damian McGuckin: > I realise that 'y - y' creates a NaN when y is either an Infinity or NaN. > Won't that also raise an INVALID exception? > Yes it will. As it should, since it calculates a new NaN where there wasn't one before (and, one layer up, csinh(0 + ∞ i) IS an invalid operation). y - y does NOT raise invalid if y already is QNaN. > What does > > x * (y - y) > > achieve that y - y does not (in the above) > The version in ctanh() sets the real part to 0 if x is zero, while the above always calculates NaN if y is not finite. Otherwise, the sign bit may be different, whatever information the sign bit of a NaN has. Ciao, Markus ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [musl] Special cases in csinh and ctanh 2024-08-06 15:46 ` Markus Wichmann @ 2024-08-07 0:51 ` Damian McGuckin 0 siblings, 0 replies; 3+ messages in thread From: Damian McGuckin @ 2024-08-07 0:51 UTC (permalink / raw) To: Markus Wichmann; +Cc: musl On Tue, 6 Aug 2024, Markus Wichmann wrote: > Am Wed, Aug 07, 2024 at 12:02:59AM +1000 schrieb Damian McGuckin: >> I realise that 'y - y' creates a NaN when y is either an Infinity or NaN. >> Won't that also raise an INVALID exception? >> > > Yes it will. That is what I assumed. > As it should, since it calculates a new NaN where there > wasn't one before (and, one layer up, csinh(0 + ? i) IS an invalid > operation). y - y does NOT raise invalid if y already is QNaN. That is what I assumed. >> What does >> >> x * (y - y) >> >> achieve that y - y does not (in the above) > > The version in ctanh() sets the real part to 0 if x is zero, while the > above always calculates NaN if y is not finite. Otherwise, the sign bit > may be different, whatever information the sign bit of a NaN has. Sorry, I was not clear enough. Looking at the case where 'x' Is zero. It is effectively ctanh: return CMPLX(x, y - y); or return CMPLX(+0, qNaN); // if x is +0 && y == an infinity + raise INVALID return CMPLX(+0, qNaN); // if x is +0 && y == qNaN return CMPLX(-0, qNaN); // if x is -0 && y == an infinity + raise INVALID return CMPLX(-0, qNaN); // if x is -0 && y == qNaN This is what I expect. It agrees with the standard. But csinh: return CMPLX(copysign(0, x * (y - y), y - y); or return CMPLX(??0, qNaN); // if y == an infinity + raise INVALID return CMPLX(??0, qNaN); // if y == qNaN I put a double question mark in front of 0 because if I have no idea to what sign the expression x*(y-y) will evaluate. I cannot see what all the extra effort buys because you end up with sort of the same result. Actually the second result potentially could have the a sign for the real part which violates the standard. Similarly, for x non-zero, you get ctanh: return CMPLX(y - y, y - y); or return CMPLX(qNaN, qNAN); // if y is an infinity + raise INVALID return CMPLX(qNaN, qNAN); // if y is a qNAN csinh: return CMPLX(y - y, x * (y - y)); or return CMPLX(qNaN, qNAN); // if y is an infinity + raise INVALID return CMPLX(qNaN, qNAN); // if y is a qNAN Again, what does the multiplication get you except more complexity. I cannot see the reason using a multiplication for it. Or am I missing something because my brain is too busy watching the Olympics? Thanks again - Damian ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-08-07 0:51 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-08-06 14:02 [musl] Special cases in csinh and ctanh Damian McGuckin 2024-08-06 15:46 ` Markus Wichmann 2024-08-07 0:51 ` Damian McGuckin
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/musl/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).