Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 06 Jan 2022 09:55:59 +0100
From: Paul Zimmermann <>
To: Szabolcs Nagy <>
Subject: Re: correctly rounded mathematical functions

       Dear Szabolcs,

> Date: Tue, 4 Jan 2022 22:12:02 +0100
> From: Szabolcs Nagy <>
> 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,

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.