Bug 58098 - wrong return value of normal_distribution::min()
Summary: wrong return value of normal_distribution::min()
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: 4.8.2
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2013-08-07 06:11 UTC by Akira Takahashi
Modified: 2013-08-07 12:17 UTC (History)
0 users

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2013-08-07 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Akira Takahashi 2013-08-07 06:11:30 UTC
In <random>(bits/random.h)'s std::normal_distribution, min() function's implementation is follow:

       * @brief Returns the greatest lower bound value of the distribution.
      min() const
      { return std::numeric_limits<result_type>::min(); }

It means return 0.0.
But, distributuon class's min() member function returns potentially return value by operator().
I think should return numeric_limits::lowest() or -numeric_limits::infinity().

libc++ and Boost.Random's implementation returns -numeric_limits::infinity().
Comment 1 Paolo Carlini 2013-08-07 08:51:44 UTC
std::numeric_limits<result_type>::min(), given that result_type is a double by default (in any case a floating point type) is __DBL_MIN__ which is exactly -infinity. If you are seeing something else, it could be that __DBL_MIN__ is broken for your target, certainly isn't for x86_64-linux, and you should file a different bug report, not having to do with the C++ library.
Comment 2 Paolo Carlini 2013-08-07 08:54:15 UTC
Never mind, I misread the value od __DBL_MIN__, I'll fix this momentarily, sorry.
Comment 3 Paolo Carlini 2013-08-07 10:08:28 UTC
Note: it's indeed debatable whether lowest or -infinity is better. For now I'm going to minimally change our code to use lowest, because we use max the other side, and infinities aren't unconditionally available.
Comment 4 Paolo Carlini 2013-08-07 12:17:23 UTC
Fixed for 4.8.2 and 4.9.0. Thanks again for the report and sorry about the lapse.