mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Damian McGuckin <damianm@esi.com.au>
To: Markus Wichmann <nullplan@gmx.net>
Cc: musl@lists.openwall.com
Subject: Re: [musl] Special cases in csinh and ctanh
Date: Wed, 7 Aug 2024 10:51:24 +1000 (AEST)	[thread overview]
Message-ID: <6143ebd-1bf-d88b-dbad-ae68ad169943@esi.com.au> (raw)
In-Reply-To: <ZrJFS7IKq3cuM6v1@voyager>

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

      reply	other threads:[~2024-08-07  0:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-06 14:02 Damian McGuckin
2024-08-06 15:46 ` Markus Wichmann
2024-08-07  0:51   ` Damian McGuckin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6143ebd-1bf-d88b-dbad-ae68ad169943@esi.com.au \
    --to=damianm@esi.com.au \
    --cc=musl@lists.openwall.com \
    --cc=nullplan@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).