summaryrefslogtreecommitdiff
path: root/devdocs/gcc~13/hex-floats.html
blob: 1e023a0051ca968444bb8b2bab17277a23ae628c (plain)
1
2
3
4
5
6
<div class="section-level-extent" id="Hex-Floats"> <div class="nav-panel"> <p> Next: <a href="fixed-point" accesskey="n" rel="next">Fixed-Point Types</a>, Previous: <a href="decimal-float" accesskey="p" rel="prev">Decimal Floating Types</a>, Up: <a href="c-extensions" accesskey="u" rel="up">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div>  <h1 class="section" id="Hex-Floats-1"><span>6.15 Hex Floats<a class="copiable-link" href="#Hex-Floats-1"> ¶</a></span></h1>  <p>ISO C99 and ISO C++17 support floating-point numbers written not only in the usual decimal notation, such as <code class="code">1.55e1</code>, but also numbers such as <code class="code">0x1.fp3</code> written in hexadecimal format. As a GNU extension, GCC supports this in C90 mode (except in some cases when strictly conforming) and in C++98, C++11 and C++14 modes. In that format the ‘<samp class="samp">0x</samp>’ hex introducer and the ‘<samp class="samp">p</samp>’ or ‘<samp class="samp">P</samp>’ exponent field are mandatory. The exponent is a decimal number that indicates the power of 2 by which the significant part is multiplied. Thus ‘<samp class="samp">0x1.f</samp>’ is 1 15/16, ‘<samp class="samp">p3</samp>’ multiplies it by 8, and the value of <code class="code">0x1.fp3</code> is the same as <code class="code">1.55e1</code>. </p> <p>Unlike for floating-point numbers in the decimal notation the exponent is always required in the hexadecimal notation. Otherwise the compiler would not be able to resolve the ambiguity of, e.g., <code class="code">0x1.f</code>. This could mean <code class="code">1.0f</code> or <code class="code">1.9375</code> since ‘<samp class="samp">f</samp>’ is also the extension for floating-point constants of type <code class="code">float</code>. </p> </div><div class="_attribution">
  <p class="_attribution-p">
    &copy; Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
    <a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Hex-Floats.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Hex-Floats.html</a>
  </p>
</div>