mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Cc: Damian McGuckin <damianm@esi.com.au>
Subject: Re: Possible Mistype in exp.c
Date: Tue, 29 Jan 2019 12:01:36 +0100	[thread overview]
Message-ID: <20190129110135.GC21289@port70.net> (raw)
In-Reply-To: <alpine.LRH.2.02.1901281753250.16424@key0.esi.com.au>

* Damian McGuckin <damianm@esi.com.au> [2019-01-28 17:59:53 +1100]:
> In 1.1.21 in exp.c
> 
>        if (x < -708.39641853226410622) {
>             /* underflow if x!=-inf */
>             FORCE_EVAL((float)(-0x1p-149/x));
                         ^^^^^^^
>             if (x < -745.13321910194110842)
> 
> The constant also appears is expf.c.
> 
> For floats and for floats, the constant
> 
> 	0x1p-149
> 
> is the smallest non-zero finite number and will do the right thing.
> 
> Using that with doubles will not trigger an underflow exception.

it's not the division that's supposed to raise the exception,
but the cast (although the division might in case of an x with
sufficiently large magnitude).

> 
> I believe that for doubles, this needs to be
> 
> 	0x1p-1074

i don't remember the reson why i wrote the code the way it is,
probably i wanted to avoid subnormal range division as it can
be a lot slower than subnormal range cast (but this code will
be slow either way which is ok since it's a rare special case)
it can also save space on hw that can load float values into
double (powerpc?), but really this is just bikeshedding.

in any case i plan to completely rewrite exp and other
important math functions:

https://www.openwall.com/lists/musl/2018/12/08/1

that implementation is >2x faster in general than the old
fdlibm code as well as more precise.


  reply	other threads:[~2019-01-29 11:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-28  6:59 Damian McGuckin
2019-01-29 11:01 ` Szabolcs Nagy [this message]
2019-01-29 11:26   ` Damian McGuckin
2019-01-29 11:43     ` Szabolcs Nagy
2019-01-30  1:18       ` Damian McGuckin
2019-01-30  9:37         ` Szabolcs Nagy
2019-01-30 11:14           ` Damian McGuckin
2019-01-30 12:19             ` Szabolcs Nagy
2019-01-30 12:44               ` Alexander Monakov
2019-01-30 14:10                 ` Szabolcs Nagy
2019-02-01 23:26                   ` Morten Welinder
2019-02-02  3:39                     ` Szabolcs Nagy
2019-02-03  2:05                       ` Morten Welinder
2019-02-03  3:07                         ` Damian McGuckin
2019-04-03  1:13                       ` Floating Point Accuracy Damian McGuckin
2019-01-30 12:56           ` Possible Mistype in exp.c Damian McGuckin
2019-01-31  0:04             ` Szabolcs Nagy
2019-01-31  0:39               ` Damian McGuckin

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=20190129110135.GC21289@port70.net \
    --to=nsz@port70.net \
    --cc=damianm@esi.com.au \
    --cc=musl@lists.openwall.com \
    /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).