<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[float &amp;amp; double:  infinity &amp;amp; NaN]]></title><description><![CDATA[<p>Hiho!</p>
<p>floats und doubles haben ja spezielle Werte fuer +- Unendlich sowie - laut <a href="http://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html" rel="nofollow">http://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html</a> zumindest auf speziellen Maschinen - auch einen eigenen &quot;Not a Number&quot; Wert.<br />
Laut folgendem Testprogramm:</p>
<pre><code class="language-cpp">#include &lt;cmath&gt;
#include &lt;iostream&gt;

using namespace std;

int main()
{
	cout &lt;&lt; &quot;NaN:\t&quot; &lt;&lt; sqrt(-1) &lt;&lt; '\n';
	cout &lt;&lt; &quot;+inf:\t&quot; &lt;&lt; 1.0/0.0 &lt;&lt; '\n';
	cout &lt;&lt; &quot;-inf:\t&quot; &lt;&lt; log(0) &lt;&lt; '\n';
}
</code></pre>
<p>Gibts auf meiner Maschine keinen eigenen NaN-Wert:</p>
<pre><code>NaN:    -1.#IND
+inf:   1.#INF
-inf:   -1.#INF
</code></pre>
<p>Gibts in C++ einen standardisierten Weg, einer float- oder double-Variable einen solchen Wert zuzuweisen? Die im obigen Link beschriebenen Makros gibts ja anscheinend erst ab C99.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/188920/float-amp-double-infinity-amp-nan</link><generator>RSS for Node</generator><lastBuildDate>Fri, 25 Sep 2026 05:07:32 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/188920.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 06 Aug 2007 11:08:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to float &amp;amp; double:  infinity &amp;amp; NaN on Mon, 06 Aug 2007 11:08:17 GMT]]></title><description><![CDATA[<p>Hiho!</p>
<p>floats und doubles haben ja spezielle Werte fuer +- Unendlich sowie - laut <a href="http://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html" rel="nofollow">http://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html</a> zumindest auf speziellen Maschinen - auch einen eigenen &quot;Not a Number&quot; Wert.<br />
Laut folgendem Testprogramm:</p>
<pre><code class="language-cpp">#include &lt;cmath&gt;
#include &lt;iostream&gt;

using namespace std;

int main()
{
	cout &lt;&lt; &quot;NaN:\t&quot; &lt;&lt; sqrt(-1) &lt;&lt; '\n';
	cout &lt;&lt; &quot;+inf:\t&quot; &lt;&lt; 1.0/0.0 &lt;&lt; '\n';
	cout &lt;&lt; &quot;-inf:\t&quot; &lt;&lt; log(0) &lt;&lt; '\n';
}
</code></pre>
<p>Gibts auf meiner Maschine keinen eigenen NaN-Wert:</p>
<pre><code>NaN:    -1.#IND
+inf:   1.#INF
-inf:   -1.#INF
</code></pre>
<p>Gibts in C++ einen standardisierten Weg, einer float- oder double-Variable einen solchen Wert zuzuweisen? Die im obigen Link beschriebenen Makros gibts ja anscheinend erst ab C99.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339465</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339465</guid><dc:creator><![CDATA[Blue-Tiger]]></dc:creator><pubDate>Mon, 06 Aug 2007 11:08:17 GMT</pubDate></item><item><title><![CDATA[Reply to float &amp;amp; double:  infinity &amp;amp; NaN on Mon, 06 Aug 2007 11:14:44 GMT]]></title><description><![CDATA[<p>Schau dir mal die Template-Klasse 'numeric_limits&lt;&gt;' an - die kannst du unter anderem nach Unendlich (numeric_limits&lt;T&gt;::infinity()) und NaN-Werten (quiet_NaN() bzw. signalling_NaN()) fragen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339469</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339469</guid><dc:creator><![CDATA[CStoll]]></dc:creator><pubDate>Mon, 06 Aug 2007 11:14:44 GMT</pubDate></item><item><title><![CDATA[Reply to float &amp;amp; double:  infinity &amp;amp; NaN on Mon, 06 Aug 2007 11:45:16 GMT]]></title><description><![CDATA[<p>Blue-Tiger schrieb:</p>
<blockquote>
<p>Hiho!</p>
<p>floats und doubles haben ja spezielle Werte fuer +- Unendlich sowie - laut <a href="http://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html" rel="nofollow">http://www.gnu.org/software/libc/manual/html_node/Infinity-and-NaN.html</a> zumindest auf speziellen Maschinen - auch einen eigenen &quot;Not a Number&quot; Wert.<br />
Laut folgendem Testprogramm:</p>
<pre><code class="language-cpp">#include &lt;cmath&gt;
#include &lt;iostream&gt;

using namespace std;

int main()
{
	cout &lt;&lt; &quot;NaN:\t&quot; &lt;&lt; sqrt(-1) &lt;&lt; '\n';
	cout &lt;&lt; &quot;+inf:\t&quot; &lt;&lt; 1.0/0.0 &lt;&lt; '\n';
	cout &lt;&lt; &quot;-inf:\t&quot; &lt;&lt; log(0) &lt;&lt; '\n';
}
</code></pre>
<p>Gibts auf meiner Maschine keinen eigenen NaN-Wert:</p>
<pre><code>NaN:    -1.#IND
+inf:   1.#INF
-inf:   -1.#INF
</code></pre>
<p>Gibts in C++ einen standardisierten Weg, einer float- oder double-Variable einen solchen Wert zuzuweisen? Die im obigen Link beschriebenen Makros gibts ja anscheinend erst ab C99.</p>
</blockquote>
<p>-1.#IND (steht für indefinite) ist auch ein NaN - typischerweise das Einzige, das unmittelbar als Ergebnis einer Rechenoperation enstehen kann - alle anderen NaNs muss man durch Bit-Manipulation künstlich erschaffen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339488</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339488</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 06 Aug 2007 11:45:16 GMT</pubDate></item><item><title><![CDATA[Reply to float &amp;amp; double:  infinity &amp;amp; NaN on Mon, 06 Aug 2007 18:49:27 GMT]]></title><description><![CDATA[<p>thx <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1339760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1339760</guid><dc:creator><![CDATA[Blue-Tiger]]></dc:creator><pubDate>Mon, 06 Aug 2007 18:49:27 GMT</pubDate></item><item><title><![CDATA[Reply to float &amp;amp; double:  infinity &amp;amp; NaN on Tue, 07 Aug 2007 12:06:59 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template&lt;typename T&gt;
   inline T getNegativeInfinity()
   {
      UBSYSTEM_STATIC_ASSERT(std::numeric_limits&lt;T&gt;::has_infinity);
      return -std::numeric_limits&lt;T&gt;::infinity();
   }
   /*=======================================================*/
   //double x = UbMath::getPositiveInfinity&lt;double&gt;();
   template&lt;typename T&gt;
   inline T getPositiveInfinity()
   {
      UBSYSTEM_STATIC_ASSERT(std::numeric_limits&lt;T&gt;::has_infinity);
      return std::numeric_limits&lt;T&gt;::infinity();
   }
   /*=======================================================*/
   //double x; bool b = UbMath::isInfinity(x);
   template&lt;typename T&gt;
   inline bool isInfinity(const T&amp; value)
   {
      if(value==getNegativeInfinity&lt;T&gt;()) return true;
      if(value==getPositiveInfinity&lt;T&gt;()) return true;
      return false;
   }
   /*=======================================================*/
   //double x = UbMath::getNaN&lt;double&gt;(x);
   template&lt;typename T&gt;
   inline T getNaN()
   {
      UBSYSTEM_STATIC_ASSERT(std::numeric_limits&lt;T&gt;::has_quiet_NaN);
      return std::numeric_limits&lt;T&gt;::quiet_NaN();
   }
   /*=======================================================*/
   //double x; bool b = UbMath::isNaN(x);
   template&lt;typename T&gt;
   inline bool isNaN(const T&amp; x)
   {
      UBSYSTEM_STATIC_ASSERT(std::numeric_limits&lt;T&gt;::has_quiet_NaN);
      return std::numeric_limits&lt;T&gt;::has_quiet_NaN &amp;&amp; (x != x);
   }
</code></pre>
<p>mit:</p>
<pre><code class="language-cpp">#define UBSYSTEM_STATIC_ASSERT(x) static_cast&lt;void&gt;(sizeof(UbSystem::static_assert&lt;x&gt;));
</code></pre>
<p>und</p>
<pre><code class="language-cpp">template&lt;bool&gt; struct static_assert;    //deklaration 
   template&lt;&gt; struct static_assert&lt;true&gt;{}; //deklaration + definition der spezialisierung fuer &quot;true&quot;
                                            //static_assert&lt;false&gt; führt zu compiler fehler, da dafür 
                                            //keine implementierung vorhanden!  //UBSYSTEM_STATIC_ASSERT(false)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1340121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1340121</guid><dc:creator><![CDATA[muffmolch]]></dc:creator><pubDate>Tue, 07 Aug 2007 12:06:59 GMT</pubDate></item></channel></rss>