<?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[casting: int -&amp;gt; double -&amp;gt; int]]></title><description><![CDATA[<pre><code>#include &lt;cassert&gt;
#include &lt;limits&gt;
int main()
{
	for ( int i = std::numeric_limits&lt;int&gt;::min(); i &lt; std::numeric_limits&lt;int&gt;::max(); ++i )
	{
		double d = i;
		int s = static_cast&lt;int&gt;( d );
		assert( s == i );
	}
}
</code></pre>
<p>Mit meiner Hardware und meinem Compiler hält die Assertion, aber ist das vom Standard garantiert? Ich hab zwar reingeguckt, konnte aber nichts finden.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/320897/casting-int-gt-double-gt-int</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 14:06:50 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/320897.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Oct 2013 12:04:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to casting: int -&amp;gt; double -&amp;gt; int on Wed, 16 Oct 2013 12:04:31 GMT]]></title><description><![CDATA[<pre><code>#include &lt;cassert&gt;
#include &lt;limits&gt;
int main()
{
	for ( int i = std::numeric_limits&lt;int&gt;::min(); i &lt; std::numeric_limits&lt;int&gt;::max(); ++i )
	{
		double d = i;
		int s = static_cast&lt;int&gt;( d );
		assert( s == i );
	}
}
</code></pre>
<p>Mit meiner Hardware und meinem Compiler hält die Assertion, aber ist das vom Standard garantiert? Ich hab zwar reingeguckt, konnte aber nichts finden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360703</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360703</guid><dc:creator><![CDATA[Dobi]]></dc:creator><pubDate>Wed, 16 Oct 2013 12:04:31 GMT</pubDate></item><item><title><![CDATA[Reply to casting: int -&amp;gt; double -&amp;gt; int on Wed, 16 Oct 2013 12:07:06 GMT]]></title><description><![CDATA[<p>Dobi schrieb:</p>
<blockquote>
<pre><code>#include &lt;cassert&gt;
#include &lt;limits&gt;
int main()
{
	for ( int i = std::numeric_limits&lt;int&gt;::min(); i &lt; std::numeric_limits&lt;int&gt;::max(); ++i )
	{
		double d = i;
		int s = static_cast&lt;int&gt;( d );
		assert( s == i );
	}
}
</code></pre>
<p>Mit meiner Hardware und meinem Compiler hält die Assertion, aber ist das vom Standard garantiert? Ich hab zwar reingeguckt, konnte aber nichts finden.</p>
</blockquote>
<p>Dein double ist von ca -2^53 bis 2^53 noch auf die Zahl genau. Dein int hat nur 32 Bit. Also reichlich Platz. Wird auf PCs auch eine ganze Weile so bleiben.<br />
Nein, der Standard garantiert das bestimmt nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360705</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360705</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 16 Oct 2013 12:07:06 GMT</pubDate></item><item><title><![CDATA[Reply to casting: int -&amp;gt; double -&amp;gt; int on Wed, 16 Oct 2013 12:11:14 GMT]]></title><description><![CDATA[<p>OK, danke.<br />
Ich hatte befürchtet, dass Dinge wie</p>
<pre><code>42 -&gt; 41.9999999 -&gt; 41
</code></pre>
<p>passieren könnten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360706</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360706</guid><dc:creator><![CDATA[Dobi]]></dc:creator><pubDate>Wed, 16 Oct 2013 12:11:14 GMT</pubDate></item><item><title><![CDATA[Reply to casting: int -&amp;gt; double -&amp;gt; int on Wed, 16 Oct 2013 12:21:10 GMT]]></title><description><![CDATA[<p>Garantiert sind für double und long double 10 signifikante Dezimalstellen, bzw. mindestends 34 bits für die Mantisse bei binärer Repräsentation (DBL_DIG aus float.h). Praktisch sind 53 Bits für double ziemlich unversell. Solange int nicht mehr als 32 bit hat, ist die Konvertierung also garantiert exakt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2360707</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2360707</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 16 Oct 2013 12:21:10 GMT</pubDate></item></channel></rss>