<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 652</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="652"></A><H4>652.
  
Compile-time evaluation of floating-point expressions
</H4>
<B>Section: </B>7.7&#160; [<A href="https://wg21.link/expr.const">expr.const</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD2
 &#160;&#160;&#160;

 <B>Submitter: </B>Jens Maurer
 &#160;&#160;&#160;

 <B>Date: </B>3 October 2007<BR>


<P>[Voted into the WP at the March, 2009 meeting.]</P>



<P>It was the intention of the constexpr proposal that implementations
be required to evaluate floating-point expressions at compile time.
This intention is not reflected in the actual wording of
7.7 [<A href="https://wg21.link/expr.const#2">expr.const</A>] paragraph 2, bullet 5:</P>

<UL><LI>

a type conversion from a floating-point type to an integral type
(7.3.11 [<A href="https://wg21.link/conv.fpint">conv.fpint</A>]) unless the conversion is directly applied
to a floating-point literal;

</LI></UL>

<P>This restriction has the effect of forbidding the use of
floating-point expressions in integral constant expressions.</P>

<P><B>Proposed resolution (June, 2008):</B></P>

<P>Delete bullet 6 of 7.7 [<A href="https://wg21.link/expr.const#2">expr.const</A>] paragraph 2:</P>

<UL><DEL><LI>a type conversion from a floating-point type to an integral
type (7.3.11 [<A href="https://wg21.link/conv.fpint">conv.fpint</A>]) unless the conversion is directly
applied to a floating-point literal;</LI></DEL></UL>

<P><B>Notes from the June, 2008 meeting:</B></P>

<P>The CWG agreed with the intent of this issue, that floating-point
calculations should be permitted in constant expressions, but acknowledged
that this opens the possibility of differing results between compile
time and run time. Such issues should be addressed non-normatively,
e.g., via a &#8220;recommended practice&#8221; note like that of C99's
6.4.4.2 or in a technical report.</P>

<P><B>Proposed resolution (August, 2008):</B></P>

<OL>
<LI><P>Delete bullet 6 of 7.7 [<A href="https://wg21.link/expr.const#2">expr.const</A>] paragraph 2:</P></LI>

<UL><DEL><LI>a type conversion from a floating-point type to an integral
type (7.3.11 [<A href="https://wg21.link/conv.fpint">conv.fpint</A>]) unless the conversion is directly
applied to a floating-point literal;</LI></DEL></UL>

<LI><P>Add a new paragraph after 7.7 [<A href="https://wg21.link/expr.const#3">expr.const</A>] paragraph 3:
</P></LI>

<BLOCKQUOTE>

<P>[<I>Note:</I> Although in some contexts constant expressions must be
evaluated during program translation, others may be evaluated during
program execution.  Since this International Standard imposes no
restrictions on the accuracy of floating-point operations, it is
unspecified whether the evaluation of a floating-point expression
during translation yields the same result as the evaluation of the
same expression (or the same operations on the same values) during
program execution. [<I>Footnote:</I> Nonetheless, implementations are
encouraged to provide consistent results, irrespective of whether the
evaluation was actually performed during translation or during program
execution. &#8212;<I>end footnote</I>] [<I>Example:</I>
</P>

<PRE>
  bool f() {
    char array[1 + int(1 + 0.2 - 0.1 - 0.1)];  //<SPAN CLASS="cmnt"> Must be evaluated during translation</SPAN>
    int size = 1 + int(1 + 0.2 - 0.1 - 0.1);   //<SPAN CLASS="cmnt"> May be evaluated at runtime</SPAN>
    return sizeof(array) == size;
  }
</PRE>

<P>It is unspecified whether the value of <TT>f()</TT> will be
<TT>true</TT> or <TT>false</TT>. &#8212;<I>end example</I>]
&#8212;<I>end note</I>]</P>

</BLOCKQUOTE>

</OL>

<BR><BR>
</BODY>
</HTML>
