Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At least if <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/is_iec559" rel="noreferrer">std::numeric_limits::is_iec559</a> (IEEE 754) is true (which guarantees, that <a href="http://en.cppreference.com/w/cpp/types/numeric_limits/has_infinity" rel="noreferrer">std::numeric_limits::has_infinity</a> is also true), you can express positive and negative infinity values the way you already stated.</p> <p><strong>Short explanation of IEEE 754-1985 infinity values from <a href="http://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_non-numbers" rel="noreferrer">Wikipedia</a>:</strong></p> <blockquote> <p>......snip......</p> <p>The biased-exponent field is filled with all 1 bits to indicate either infinity or an invalid result of a computation.</p> <p><strong>Positive and negative infinity</strong></p> <p>Positive and negative infinity are represented thus:</p> <pre><code> sign = 0 for positive infinity, 1 for negative infinity. biased exponent = all 1 bits. fraction = all 0 bits. </code></pre> <p>......snip......</p> </blockquote> <p><strong>Assertions</strong></p> <p>The following example will either work as expected, or cause a compile time error in case the target platform does not support IEEE 754 floats.</p> <pre><code>#include &lt;cstdlib&gt; #include &lt;cmath&gt; #include &lt;cassert&gt; #include &lt;limits&gt; int main(void) { //Asserts floating point compatibility at compile time static_assert(std::numeric_limits&lt;float&gt;::is_iec559, "IEEE 754 required"); //C99 float negative_infinity1 = -INFINITY; float negative_infinity2 = -1 * INFINITY; float negative_infinity3 = -std::numeric_limits&lt;float&gt;::infinity(); float negative_infinity4 = -1 * std::numeric_limits&lt;float&gt;::infinity(); assert(std::isinf(negative_infinity1) &amp;&amp; negative_infinity1 &lt; std::numeric_limits&lt;float&gt;::lowest()); assert(std::isinf(negative_infinity2) &amp;&amp; negative_infinity2 &lt; std::numeric_limits&lt;float&gt;::lowest()); assert(std::isinf(negative_infinity3) &amp;&amp; negative_infinity3 &lt; std::numeric_limits&lt;float&gt;::lowest()); assert(std::isinf(negative_infinity4) &amp;&amp; negative_infinity4 &lt; std::numeric_limits&lt;float&gt;::lowest()); return EXIT_SUCCESS; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload