<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>CLR and floating point: Some answers to common questions</title><link>http://blogs.msdn.com/davidnotario/archive/2005/08/08/449092.aspx</link><description>Some very common questions I get from customers regarding floating point are: - I get different results when compiling with optimizations vs without optimizations! - My == checks are failing when the expressions are the same! The answer for this question</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: CLR and floating point: Some answers to common questions</title><link>http://blogs.msdn.com/davidnotario/archive/2005/08/08/449092.aspx#449369</link><pubDate>Tue, 09 Aug 2005 11:34:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:449369</guid><dc:creator>Chris Nahr</dc:creator><description>Why not educate the programmers about FP calculations instead? It's a well-known fact that FP variables must never be compared for equality, unless they result from a constant assignment. Otherwise, you must compare their absolute difference against an epsilon that represents the desired precision.&lt;br&gt;&lt;br&gt;If you write FP code using crutches such as fp:precise or fp:strict you get poorly performing code that will break as soon as someone uses a different compiler or different compiler switches. I don't quite see the point, frankly -- other than perhaps reducing Microsoft's support incidents.</description></item><item><title>re: CLR and floating point: Some answers to common questions</title><link>http://blogs.msdn.com/davidnotario/archive/2005/08/08/449092.aspx#449440</link><pubDate>Tue, 09 Aug 2005 17:07:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:449440</guid><dc:creator>Dmitriy</dc:creator><description>fp:precise or fp:strict is not crutches but makes wrighting &amp;quot;correct&amp;quot; code much easier. &lt;br&gt;Chris it just shows you never.&lt;br&gt;&lt;br&gt;&lt;br&gt;BTW 2 days before your blog I blogged on the same issue :)&lt;br&gt;&lt;br&gt;&lt;br&gt;David, could you explain some of the optimization desicisions and specifically why is it hard to inline value type members.&lt;br&gt;&lt;br&gt;</description></item><item><title>re: CLR and floating point: Some answers to common questions</title><link>http://blogs.msdn.com/davidnotario/archive/2005/08/08/449092.aspx#449490</link><pubDate>Tue, 09 Aug 2005 18:52:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:449490</guid><dc:creator>davidnotario</dc:creator><description>Chris, the C++ story is better now than before. Pre Whidbey they wouldn't respect casts. At least now they don't do things like that.&lt;br&gt;&lt;br&gt;Every time this issue comes up, we have to camps:&lt;br&gt;&lt;br&gt;a) People that want the same floating point IL to give exactly the same results on all platforms and JITs.&lt;br&gt;&lt;br&gt;b) People that want compilers to be able to take full advantage of the HW.&lt;br&gt;&lt;br&gt;Both of these options are pretty extreme. a) is ideal, but not practical due to performance issues. Make b) too 'hard' for the developer and you are not offering a compelling platform.  A similar decision has happened regarding the memory model of the CLR: a) would mean bad performance, b) as proposed by HW vendors (free write and read reordering) makes writing code for the platform very hard. What you really want is something that is easy to get right (so the platform is productive), but that doesn't leave performance on the table for advanced developers. I think C++ is closer to that model today for floating point with their /fp options: By default, the behavior is more coherent than in their previous versions, but it still has the /fp:fast option when you care more about speed.&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;</description></item><item><title>re: CLR and floating point: Some answers to common questions</title><link>http://blogs.msdn.com/davidnotario/archive/2005/08/08/449092.aspx#449494</link><pubDate>Tue, 09 Aug 2005 18:56:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:449494</guid><dc:creator>davidnotario</dc:creator><description>Dmitry:&lt;br&gt;&lt;br&gt;It's not a design decision, it's a limitation in how the x86 JIT compiler was built which is expensive to fix now (ie, some major rehaul). It's on our radar, we hate that we have these limitations, but in a limited time budget, we have preferred to fix 20 other issues than concentrate a lot of effort in this particular one. </description></item><item><title>re: CLR and floating point: Some answers to common questions</title><link>http://blogs.msdn.com/davidnotario/archive/2005/08/08/449092.aspx#450720</link><pubDate>Fri, 12 Aug 2005 09:35:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:450720</guid><dc:creator>Chris Nahr</dc:creator><description>Hmm, I guess I'm extreme then. :) What I'd really like to see:&lt;br&gt;&lt;br&gt;1. A warning when the C# compiler encounters any direct comparisons between floating-point types. Better yet, different warnings depending on whether one operand is 0.0 or 1.0.&lt;br&gt;&lt;br&gt;2. A standard method to perform FP comparisons with a given epsilon, or with a default epsilon based on the operand type. Let's call it Math.CompareTo(a, b, epsilon) which results in 0 if abs(a-b) &amp;lt;= epsilon, etc.&lt;br&gt;&lt;br&gt;That solution would be fast, reliable, portable... you name it. No fundamental changes to the CLR or C# compiler would be required. And when people asked about weird FP results you could just tell them to use Math.CompareTo.&lt;br&gt;&lt;br&gt;Maybe this would be a nice idea in addition to whatever FPU-specific options you think of adding?</description></item><item><title>Tim Van Wassenhove  &amp;raquo; Archive  &amp;raquo; About additional precision and unpredicted behaviour...</title><link>http://blogs.msdn.com/davidnotario/archive/2005/08/08/449092.aspx#3548780</link><pubDate>Tue, 26 Jun 2007 20:27:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3548780</guid><dc:creator>Tim Van Wassenhove  » Archive  » About additional precision and unpredicted behaviour...</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.timvw.be/about-additional-precision-and-unpredicted-behaviour/"&gt;http://www.timvw.be/about-additional-precision-and-unpredicted-behaviour/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title> David Notario s WebLog CLR and floating point Some answers to common | storage bench</title><link>http://blogs.msdn.com/davidnotario/archive/2005/08/08/449092.aspx#9782324</link><pubDate>Fri, 19 Jun 2009 10:51:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9782324</guid><dc:creator> David Notario s WebLog CLR and floating point Some answers to common | storage bench</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://thestoragebench.info/story.php?id=7532"&gt;http://thestoragebench.info/story.php?id=7532&lt;/a&gt;&lt;/p&gt;
</description></item></channel></rss>