<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 4084: std::fixed ignores std::uppercase</title>
<meta property="og:title" content="Issue 4084: std::fixed ignores std::uppercase">
<meta property="og:description" content="C++ library issue. Status: WP">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4084.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#WP">WP</a> status.</em></p>
<h3 id="4084"><a href="lwg-defects.html#4084">4084</a>. <code>std::fixed</code> ignores <code>std::uppercase</code></h3>
<p><b>Section:</b> 28.3.4.3.3.3 <a href="https://wg21.link/facet.num.put.virtuals">[facet.num.put.virtuals]</a> <b>Status:</b> <a href="lwg-active.html#WP">WP</a>
 <b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2024-04-30 <b>Last modified:</b> 2024-11-28</p>
<p><b>Priority: </b>3
</p>
<p><b>View other</b> <a href="lwg-index-open.html#facet.num.put.virtuals">active issues</a> in [facet.num.put.virtuals].</p>
<p><b>View all other</b> <a href="lwg-index.html#facet.num.put.virtuals">issues</a> in [facet.num.put.virtuals].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#WP">WP</a> status.</p>
<p><b>Discussion:</b></p>
<p>
In Table 114 &ndash; Floating-point conversions [tab:facet.num.put.fp]
we specify that a floating-point value should be printed as if by <code class='backtick'>%f</code>
when <code>(flags &amp; floatfield) == fixed</code>.
This ignores whether <code class='backtick'>uppercase</code> is also set in <code class='backtick'>flags</code>,
meaning there is no way to use the conversion specifier <code class='backtick'>%F</code>
that was added to <code class='backtick'>printf</code> in C99.
</p>
<p>
That's fine for finite values, because 1.23 in fixed format has
no exponent character and no hex digits that would need to use uppercase.
But <code class='backtick'>%f</code> and <code class='backtick'>%F</code> are not equivalent for non-finite values,
because <code class='backtick'>%F</code> prints <code class='backtick'>"NAN"</code> and <code class='backtick'>"INF"</code> (or <code class='backtick'>"INFINITY"</code>).
It seems there is no way to print <code class='backtick'>"NAN"</code> or <code class='backtick'>"INF"</code> using <code class='backtick'>std::num_put</code>.
</p>
<p>
Libstdc++ and MSVC print <code class='backtick'>"inf"</code> for the following code,
but libc++ prints <code class='backtick'>"INF"</code> which I think is non-conforming:
</p>
<pre><code>    std::cout &lt;&lt; std::uppercase &lt;&lt; std::fixed &lt;&lt; std::numeric_limits&lt;double&gt;::infinity();
</code></pre>
<p>
The libc++ behaviour seems more useful and less surprising.
</p>

<p><i>[2024-05-08; Reflector poll]</i></p>

<p>
Set priority to 3 after reflector poll. Send to LEWG.
</p>
<p><i>[2024-09-17; LEWG mailing list vote]</i></p>

<p>
Set status to Open after LEWG approved the proposed change.
</p>
<p><i>[2024-09-19; Reflector poll]</i></p>

<p>
Set status to Tentatively Ready after eight votes in favour during reflector poll.
</p>

<p><i>[Wrocław 2024-11-23; Status changed: Voting &rarr; WP.]</i></p>



<p id="res-4084"><b>Proposed resolution:</b></p>
<p>
This wording is relative to <a href="https://wg21.link/N4981" title=" Working Draft, Programming Languages — C++">N4981</a>.
</p>
<ol>
<li><p>Modify 28.3.4.3.3.3 <a href="https://wg21.link/facet.num.put.virtuals">[facet.num.put.virtuals]</a> as indicated:</p>

<blockquote>
<table style="border: 1px solid">
<caption style="caption-side: top">
Table 114 &ndash; Floating-point conversions [tab:facet.num.put.fp]
</caption>
<tr style="text-align: center">
<th style="border-bottom: 1px solid">State</th>
<th style="border-bottom: 1px solid"><code class='backtick'>stdio</code> equivalent</th>
</tr>
<tr>
<td>
<code class='backtick'>floatfield == ios_base::fixed</code> <ins><code>&amp;&amp; !uppercase</code></ins>
</td>
<td style="text-align: center"><code class='backtick'>%f</code></td>
</tr>
<tr>
<td><ins><code class='backtick'>floatfield == ios_base::fixed</code></ins></td>
<td style="text-align: center"><ins><code class='backtick'>%F</code></ins></td>
</tr>
<tr>
<td><code>floatfield == ios_base::scientific &amp;&amp; !uppercase</code></td>
<td style="text-align: center"><code class='backtick'>%e</code></td>
</tr>
<tr>
<td><code>floatfield == ios_base::scientific</code></td>
<td style="text-align: center"><code class='backtick'>%E</code></td>
</tr>
<tr>
<td>
<code>
floatfield == (ios_base::fixed | ios_base::scientific)` &amp;&amp; !uppercase
</code>
</td>
<td style="text-align: center"><code class='backtick'>%a</code></td>
</tr>
<tr>
<td><code>floatfield == (ios_base::fixed | ios_base::scientific)</code></td>
<td style="text-align: center"><code class='backtick'>%A</code></td>
</tr>
<tr>
<td><code class='backtick'>!uppercase</code></td>
<td style="text-align: center"><code class='backtick'>%g</code></td>
</tr>
<tr>
<td><em>otherwise</em></td>
<td style="text-align: center"><code class='backtick'>%G</code></td>
</tr>
</table>
</blockquote>
</li>
</ol>






</body>
</html>
