<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 2730: numeric_limits primary template definition</title>
<meta property="og:title" content="Issue 2730: numeric_limits primary template definition">
<meta property="og:description" content="C++ library issue. Status: Open">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue2730.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#Open">Open</a> status.</em></p>
<h3 id="2730"><a href="lwg-active.html#2730">2730</a>. <code>numeric_limits</code> primary template definition</h3>
<p><b>Section:</b> 17.3.5 <a href="https://wg21.link/numeric.limits">[numeric.limits]</a> <b>Status:</b> <a href="lwg-active.html#Open">Open</a>
 <b>Submitter:</b> Richard Smith <b>Opened:</b> 2016-06-09 <b>Last modified:</b> 2023-04-18</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#numeric.limits">active issues</a> in [numeric.limits].</p>
<p><b>View all other</b> <a href="lwg-index.html#numeric.limits">issues</a> in [numeric.limits].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#Open">Open</a> status.</p>
<p><b>Discussion:</b></p>
<p>
I've received this report at the <a href="mailto:cxxeditor@gmail.com">project editor mail alias</a>, and it seems like it may be worthy of a LWG issue:
</p>
<blockquote class="note">
<p>
I recently had this problem: 
</p>
<ul>
<li>I was storing data in a vector of <code>__uint128_t</code>s</li>
<li>I used a sorting library which used <code>numeric_limits&lt;T&gt;::max()</code> as a sentinel value</li>
<li>GCC's libstdc++ provides a <code>numeric_limits</code> specialisation for that type, but</li>
<li>Clang's libc++ does not.</li>
</ul>
<p>
This broke the sorting for me on different platforms, and it was quite difficult to determine why. If the default 
<code>numeric_limits</code> didn't default to <code>0</code>s and <code>false</code> values (18.3.2.4 of N4582), and instead 
<code>static_assert</code>ed, causing my code to not compile, I would have found the solution immediately.
<p/>
I know that <code>__uint128_t</code> is non-standard, so neither GCC nor Clang is doing the wrong thing nor the right thing 
here. I could just submit a patch to libc++ providing the specialisations, but it doesn't fix the problem at its core.
<p/>
I am wondering, what is the rationale behind the defaults being <code>0</code> and <code>false</code>? It seems like it is 
inviting a problem for any future numeric types, whether part of a library, compiler extension, and possibly even 
future updates to C++'s numeric types. I think it would be much better to prevent code that tries to use 
unspecified <code>numeric_limits</code> from compiling.
</p>
</blockquote>
<p>
An alternative to this suggestion would be to still define the primary template, but not provide any of the members 
except <code>is_specialized</code>. Either way, this would make <code>numeric_limits</code> members SFINAEable.
<p/>
Along the same lines, one might wonder why the members that only make sense for floating-point types are required to 
be defined to nonsense values for integer types.
</p>

<p><i>[2016-11-12, Issaquah]</i></p>

<p>Sat PM: This looks like a good idea. Jonathan and Marshall will do post C++17 implementations and report back.</p>

<p><i>[2018-11 San Diego Thursday night issue processing]</i></p>

<p>See Walter's paper <a href="https://wg21.link/P0437" title=" Numeric Traits for the Standard Library">P0437</a> for ideas and/or future directions.</p>

<p><i>[2023-04]</i></p>

<p>See Walter's paper <a href="https://wg21.link/P1841" title=" Wording for Individually Specializable Numeric Traits">P1841</a> for the preferred direction.</p>


<p id="res-2730"><b>Proposed resolution:</b></p>





</body>
</html>
