<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2168: Inconsistent specification of uniform_real_distribution constructor</title>
<meta property="og:title" content="Issue 2168: Inconsistent specification of uniform_real_distribution constructor">
<meta property="og:description" content="C++ library issue. Status: C++17">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2168.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++17">C++17</a> status.</em></p>
<h3 id="2168"><a href="lwg-defects.html#2168">2168</a>. Inconsistent specification of <code>uniform_real_distribution</code> constructor</h3>
<p><b>Section:</b> 29.5.9.2.2 <a href="https://wg21.link/rand.dist.uni.real">[rand.dist.uni.real]</a> <b>Status:</b> <a href="lwg-active.html#C++17">C++17</a>
 <b>Submitter:</b> Marshall Clow <b>Opened:</b> 2012-07-14 <b>Last modified:</b> 2017-07-30</p>
<p><b>Priority: </b>3
</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++17">C++17</a> status.</p>
<p><b>Discussion:</b></p>

<p>
uniform_real says in 29.5.9.2.2 <a href="https://wg21.link/rand.dist.uni.real">[rand.dist.uni.real]</a> p1:
</p>
<blockquote><p>
A <code>uniform_real_distribution</code> random number distribution produces random numbers <code>x</code>, <code>a &le; x &lt; b</code>,
</p></blockquote>
<p>
but also that (29.5.9.2.2 <a href="https://wg21.link/rand.dist.uni.real">[rand.dist.uni.real]</a> p2):
</p>
<blockquote><pre>
explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
</pre><blockquote><p>
-2- <i>Requires</i>: <code>a &le; b</code> and <code>b - a &le; numeric_limits&lt;RealType&gt;::max()</code>.
</p>
</blockquote></blockquote>
<p>
If you construct a <code>uniform_real_distribution&lt;RealType&gt;(a, b)</code> where there are no representable 
numbers between 'a' and 'b' (using <code>RealType</code>'s representation) then you cannot satisfy 
29.5.9.2.2 <a href="https://wg21.link/rand.dist.uni.real">[rand.dist.uni.real]</a>.
<p/>
An obvious example is when <code>a == b</code>.
</p>

<p><i>[2014-11-04 Urbana]</i></p>

<p>
Jonathan provides wording.
</p>

<p><i>[2014-11-08 Urbana]</i></p>

<p>
Moved to Ready with the note.
</p>
<p>
There remains concern that the constructors are permitting
values that may (or may not) be strictly outside the domain
of the function, but that is a concern that affects the
design of the random number facility as a whole, and should
be addressed by a paper reviewing and addressing the whole
clause, not picked up in the issues list one distribution
at a time.  It is still not clear that such a paper would be
uncontroversial.
</p>



<p id="res-2168"><b>Proposed resolution:</b></p>
<p>
This wording is relative to N4140.
</p>

<ol>
<li><p>Add a note after paragraph 1 before the synopsis in 29.5.9.2.2 <a href="https://wg21.link/rand.dist.uni.real">[rand.dist.uni.real]</a>:</p>

<blockquote><p>
-1- A <code>uniform_real_distribution</code> random number distribution produces random numbers 
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>x</mi>
</math>,
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>a</mi><mo>&le;</mo><mi>x</mi><mo>&lt;</mo><mi>b</mi>
</math>,
distributed according to the constant probability density function
</p>
<blockquote>
<p>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>p</mi><mrow><mo>(</mo><mi>x</mi><mo>|</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>)</mo></mrow>
<mo>=</mo>
<mrow>
<mn>1</mn><mo>&#x2215;</mo><mo>(</mo><mi>b</mi><mo>-</mo><mi>a</mi><mo>)</mo>
</mrow>
</math>
.
</p>
</blockquote>
<p>
<ins>[<i>Note</i>: This implies that <math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>p</mi><mrow><mo>(</mo><mi>x</mi><mo>|</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>)</mo></mrow> 
</math> is undefined when <code>a == b</code>. &mdash; <i>end note</i>]</ins>
</p></blockquote>
<blockquote class="note">
<p>
<i>Drafting note</i>: <math xmlns="http://www.w3.org/1998/Math/MathML">
<mi>p</mi><mrow><mo>(</mo><mi>x</mi><mo>|</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>)</mo></mrow> 
</math> should be in math font, and <code>a == b</code> should be in code font.
</p>
</blockquote>
</li>
</ol>





</body>
</html>
