mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Implementing csqrtl()
@ 2022-07-04  9:35 Nikolaos Chatzikonstantinou
  2022-07-04 11:09 ` [musl] " Nikolaos Chatzikonstantinou
  0 siblings, 1 reply; 6+ messages in thread
From: Nikolaos Chatzikonstantinou @ 2022-07-04  9:35 UTC (permalink / raw)
  To: musl

Hello list,

I wanted to implement some function from
which is an open issue in the wiki.

One of the missing complex functions is csqrtl(), the long double
version of complex square root. I was able to find a 1987 article from
W. Kahan, titled "Branch cuts for complex elementary functions." that
contained an implementation for complex square root for arbitrary
floating-point numbers. In this e-mail you'll find an attached git
patch with the implementation.

As a very basic test, I wrote a program that produces random
complex numbers in the square [0, N] x [0, N] for N=1,100 and
calculates csqrt{,f,l}() with my implementation, glibc and the
arbitrary precision mpc_sqrt() from MPC,

Glibc stays almost within 1 ulp in float and double, but my
implementation wasn't so good with float. The double
implementation seems to get the exact same results as glibc does.

I was not able to even test the long double version with this
method, because I did not write the code that produces random
long double complex numbers yet.

There's a few things that I don't quite understand here. One is, I'm
not sure why Kahan's implementation is accurate. For another, I don't
know how to do any sort of speed tests; I've read online that
microbenchmarking is not reproducible for math functions, and so
google's benchmark <> does not seem
to help. Of course I'm aware that the C implementation would not be
the one used in most systems, as the assembly implementations are
usually better. Finally, I don't know what the right way to test an
implementation for accuracy is: whether by using automation or writing
proofs. It seems the state of the art has evolved quite a bit from
1987, and yet I don't know where to look for information on this
topic, as it seems very specific to chips & the C std lib.

Feel free to provide any sort of criticism. I'm e-mailing this
implementation for the purpose of starting a discussion, but I'm
hoping to be able to contribute something in the near future.

Nikolaos Chatzikonstantinou

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

end of thread, other threads:[~2022-07-05 16:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-04  9:35 [musl] Implementing csqrtl() Nikolaos Chatzikonstantinou
2022-07-04 11:09 ` [musl] " Nikolaos Chatzikonstantinou
2022-07-05  9:37   ` Szabolcs Nagy
2022-07-05 14:28     ` Nikolaos Chatzikonstantinou
2022-07-05 15:35       ` Markus Wichmann
2022-07-05 16:14         ` Nikolaos Chatzikonstantinou

Code repositories for project(s) associated with this public inbox

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