From: Paul Zimmermann <Paul.Zimmermann@inria.fr>
To: Szabolcs Nagy <firstname.lastname@example.org>
Cc: email@example.com, firstname.lastname@example.org, email@example.com,
Subject: Re: [musl] correctly rounded mathematical functions
Date: Thu, 06 Jan 2022 09:55:59 +0100 [thread overview]
Message-ID: <firstname.lastname@example.org> (raw)
In-Reply-To: <20220104211202.GB1320090@port70.net> (message from Szabolcs Nagy on Tue, 4 Jan 2022 22:12:02 +0100)
> Date: Tue, 4 Jan 2022 22:12:02 +0100
> From: Szabolcs Nagy <email@example.com>
> i only looked at cr_asinf:
thank you for looking! This is much appreciated.
> 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.
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]
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:
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
* 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
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).