public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kretz at kde dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/67011] division by zero in std::exponential_distribution
Date: Mon, 27 Jul 2015 14:25:00 -0000	[thread overview]
Message-ID: <bug-67011-4-Kzw5j4C54p@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-67011-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67011

Matthias Kretz <kretz at kde dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kretz at kde dot org

--- Comment #3 from Matthias Kretz <kretz at kde dot org> ---
The problem is that (result_type(1) - __aurng()) must never be zero (because
std::log might raise FE_DIVBYZERO for std::log(0)). If __aurng() is a
distribution guaranteed to exclude result_type(1) then this works fine. AFAIK
std::generate_canoncial<float> sometimes generates a 1 (cf.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63176).

Also, I'm wondering whether the 1 - rng wouldn't reduce the randomness.
Consider:
std::log(numeric_limits<float>::min()) -> -87.3365478515625
std::log(1.f - nextafter(1.f, 0.f))    -> -16.635532379150390625
IIUC, the effect of log(1 - rng) is that the distance between random values
from std::exponential_distribution is considerable larger than for log(rng).


      parent reply	other threads:[~2015-07-27 14:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-67011-4@http.gcc.gnu.org/bugzilla/>
2015-07-26 20:32 ` redi at gcc dot gnu.org
2015-07-26 20:50 ` redi at gcc dot gnu.org
2015-07-27 14:25 ` kretz at kde dot org [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=bug-67011-4-Kzw5j4C54p@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).