mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] asinf pulls in sqrt (double version)
@ 2022-03-10 15:44 Norbert Lange
  2022-03-10 17:05 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Norbert Lange @ 2022-03-10 15:44 UTC (permalink / raw)
  To: musl

Hello,

pulled some of the math routines for a float-only project,
what I found is that asinf pulls in sqrt, and I cant tell whether this
is necessary because of precision.

The line is in src/math/asinf.c:
s = sqrt(z);

Regards, Norbert

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] asinf pulls in sqrt (double version)
  2022-03-10 15:44 [musl] asinf pulls in sqrt (double version) Norbert Lange
@ 2022-03-10 17:05 ` Rich Felker
  2022-03-10 17:36   ` Norbert Lange
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2022-03-10 17:05 UTC (permalink / raw)
  To: Norbert Lange; +Cc: musl

On Thu, Mar 10, 2022 at 04:44:37PM +0100, Norbert Lange wrote:
> Hello,
> 
> pulled some of the math routines for a float-only project,
> what I found is that asinf pulls in sqrt, and I cant tell whether this
> is necessary because of precision.
> 
> The line is in src/math/asinf.c:
> s = sqrt(z);

It looks like it's intentional -- s has type double and is used in an
expression where the additional precision would make a difference:

	x = pio2 - 2*(s+s*R(z));

I suspect it would be more work (and slower) to get suitable precision
without the double intermediate here, but I have not done the analysis
myself.

Rich

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] asinf pulls in sqrt (double version)
  2022-03-10 17:05 ` Rich Felker
@ 2022-03-10 17:36   ` Norbert Lange
  0 siblings, 0 replies; 3+ messages in thread
From: Norbert Lange @ 2022-03-10 17:36 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl

Am Do., 10. März 2022 um 18:05 Uhr schrieb Rich Felker <dalias@libc.org>:
>
> On Thu, Mar 10, 2022 at 04:44:37PM +0100, Norbert Lange wrote:
> > Hello,
> >
> > pulled some of the math routines for a float-only project,
> > what I found is that asinf pulls in sqrt, and I cant tell whether this
> > is necessary because of precision.
> >
> > The line is in src/math/asinf.c:
> > s = sqrt(z);
>
> It looks like it's intentional -- s has type double and is used in an
> expression where the additional precision would make a difference:
>
>         x = pio2 - 2*(s+s*R(z));
>
> I suspect it would be more work (and slower) to get suitable precision
> without the double intermediate here, but I have not done the analysis
> myself.

the extended precision is necessary *if* "2*(s+s*R(z))" is close to pio2,
*or* s is close to -1 * s*R(z), so that it would cancel out several of
the highest bits.

Given that this block results in 1 > |x| >= 0.5, which is atleast
0.5 away from pio2 and 0, my gut tells me that this is not the case.

So my argument would be that sqrtf might be viable without affecting
the result at all or more than one ulp.
I know that this doesn't mean much without a proof.

Any hints where the algorithm is coming from?

Norbert

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-10 17:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10 15:44 [musl] asinf pulls in sqrt (double version) Norbert Lange
2022-03-10 17:05 ` Rich Felker
2022-03-10 17:36   ` Norbert Lange

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).