From: Paul Zimmermann <Paul.Zimmermann@inria.fr>
To: Szabolcs Nagy <nsz@port70.net>
Cc: dalias@libc.org, musl@lists.openwall.com, sibid@uvic.ca,
christoph.lauter@christoph-lauter.org,
Jean-Michel.Muller@ENS-LYON.FR
Subject: Re: [musl] correctly rounded mathematical functions
Date: Thu, 06 Jan 2022 09:55:59 +0100 [thread overview]
Message-ID: <mwwnjdz1i8.fsf@tomate.loria.fr> (raw)
In-Reply-To: <20220104211202.GB1320090@port70.net> (message from Szabolcs Nagy on Tue, 4 Jan 2022 22:12:02 +0100)
Dear Szabolcs,
> Date: Tue, 4 Jan 2022 22:12:02 +0100
> From: Szabolcs Nagy <nsz@port70.net>
>
> i only looked at cr_asinf:
thank you for looking! This is much appreciated.
> float
> cr_asinf (float x)
> {
> /* deal here with NaN, +Inf and -Inf */
>
> yeah that can be tricky and different across math libs.
> (errno vs no errno, wrapper to handle special cases vs no wrapper etc)
indeed, and that will be specific to each libm
> to minimize branches you may want to merge it with the |x|>1 check below.
>
> double absx = fabsf (x), y;
> if (absx > 1)
> return sqrt (-1.0); /* NaN */
> ...
I tried to merge the detection of NaN, Inf with the case |x| > 1 using
the glibc macro asuint, but it was not faster (at least for glibc make bench).
> this reminds me that musl does not use compiler builtins at build time,
> which means fabsf, sqrt are extern calls, which means this will not be
> a leaf function (note: sqrt is not a tail call here because of the
> implicit conversion, i think it should be sqrtf).
then probably for musl it would be faster to have the following:
double absx = (x > 0) ? x : -x;
we can probably define macros for this, say CORE_MATH_FABS, that would
be instantiated differently for each libm.
> i prefer to tail call a function with descriptive name when handling
> errors, but it does not always work out well: e.g. underflow can be
> tricky if you want to ensure that an exact subnormal result does not
> raise it (e.g. powf(2, -140)), but inexact does.
yes, sqrt (-1.0) was just a portable way to generate NaN. This code
will evolve over time with the feedback we get.
Best regards,
Paul
prev parent reply other threads:[~2022-01-06 8:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-03 13:07 Paul Zimmermann
2022-01-04 0:04 ` Damian McGuckin
2022-01-04 2:29 ` Rich Felker
2022-01-04 14:19 ` Paul Zimmermann
2022-01-04 21:12 ` Szabolcs Nagy
2022-01-06 8:55 ` Paul Zimmermann [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=mwwnjdz1i8.fsf@tomate.loria.fr \
--to=paul.zimmermann@inria.fr \
--cc=Jean-Michel.Muller@ENS-LYON.FR \
--cc=christoph.lauter@christoph-lauter.org \
--cc=dalias@libc.org \
--cc=musl@lists.openwall.com \
--cc=nsz@port70.net \
--cc=sibid@uvic.ca \
/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).