<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: More Floating Point Madness</title>
	<atom:link href="http://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/</link>
	<description>Thoughts, rants, and even some code from the mind of Barney Boisvert.</description>
	<lastBuildDate>Thu, 11 Sep 2014 09:58:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ben Nadel</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187766</link>
		<dc:creator>Ben Nadel</dc:creator>
		<pubDate>Fri, 07 Aug 2009 14:01:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187766</guid>
		<description>I&#039;ve also seen this error pop up when dealing with numeric date/times. So frustrating.</description>
		<content:encoded><![CDATA[<p>I've also seen this error pop up when dealing with numeric date/times. So frustrating.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187576</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Wed, 05 Aug 2009 16:59:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187576</guid>
		<description>My point, which I clearly didn&#039;t articulate very well, was that it&#039;s quite possible for your seemingly innocuous code to be corrupted by floating point errors.  Boundary conditions in your tests need to take this into consideration, for example.

Further, because the error can manifest itself within CFML constructs that you (the developer) have no control over, it can be hard to see both that a problem could exist or how to change exact comparisons to proximity comparisons.  The fixFloatingPoint() UDF is designed to stably align a floating point value into a proximity value, but it has to be used explicitly.

Another way to do proximity alignment (if you can&#039;t remove the floating point computations), is to change bounds.  For example, modify the first CFLOOP above to this (adding most of an extra step):

&lt;pre&gt;
&lt;cfloop from=&quot;#bounds.lower#&quot; to=&quot;#bounds.upper&lt;span style=&quot;color:#00f&quot;&gt; + bounds.interval * 0.9&lt;/span&gt;#&quot; index=&quot;i&quot; step=&quot;#bounds.interval#&quot;&gt;
  #i#&lt;br /&gt;
&lt;/cfloop&gt;
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>My point, which I clearly didn't articulate very well, was that it's quite possible for your seemingly innocuous code to be corrupted by floating point errors.  Boundary conditions in your tests need to take this into consideration, for example.</p>
<p>Further, because the error can manifest itself within CFML constructs that you (the developer) have no control over, it can be hard to see both that a problem could exist or how to change exact comparisons to proximity comparisons.  The fixFloatingPoint() UDF is designed to stably align a floating point value into a proximity value, but it has to be used explicitly.</p>
<p>Another way to do proximity alignment (if you can't remove the floating point computations), is to change bounds.  For example, modify the first CFLOOP above to this (adding most of an extra step):</p>
<pre>
&lt;cfloop from="#bounds.lower#" to="#bounds.upper<span style="color:#00f"> + bounds.interval * 0.9</span>#" index="i" step="#bounds.interval#">
  #i#&lt;br />
&lt;/cfloop>
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Woodward</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187574</link>
		<dc:creator>Matt Woodward</dc:creator>
		<pubDate>Wed, 05 Aug 2009 16:23:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187574</guid>
		<description>Just confirming OpenBD behaves the same way.

This may not be generally applicable to all situations, but in this particular case you could multiply the loop bounds by 10, use a step of 2 instead of .2, and multiply by .1 within the loop to get the values you want, which behaves correctly. Just another idea.</description>
		<content:encoded><![CDATA[<p>Just confirming OpenBD behaves the same way.</p>
<p>This may not be generally applicable to all situations, but in this particular case you could multiply the loop bounds by 10, use a step of 2 instead of .2, and multiply by .1 within the loop to get the values you want, which behaves correctly. Just another idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187559</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Wed, 05 Aug 2009 12:50:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187559</guid>
		<description>I brought this up a while ago on the Railo list.  (I found that same problem when using Val() and floating point equality).  Sean replied to me with the below:

&quot;Not exactly a helpful observation but I would point out that it is
never really safe to use equality tests on floating point numbers...

I guess I would have to ask *why* you are trying to test for floating
point equality rather than just a suitable proximity?

Have a play with this to see why comparing floating point numbers can
be problematic:

http://babbage.cs.qc.edu/IEEE-754/Decimal.html

If you enter 0.1, you&#039;ll see the 32-bit representation is different
for rounded vs non-rounded but if you enter 0.01 you&#039;ll see it is the
same for rounded vs non-rounded (and neither are equal to 0.01 within
the precision allowed by 32-bits). As you can imagine, lots of factors
come into play when manipulating floating point numbers - how constant
expressions are reduced, how optimization is performed on
subexpressions...&quot;

In my case I was able to change my code to test for suitable proximity. 

(I also checked the Railo source and it doesn&#039;t use BigDecimal for floating point values)</description>
		<content:encoded><![CDATA[<p>I brought this up a while ago on the Railo list.  (I found that same problem when using Val() and floating point equality).  Sean replied to me with the below:</p>
<p>"Not exactly a helpful observation but I would point out that it is<br />
never really safe to use equality tests on floating point numbers&#8230;</p>
<p>I guess I would have to ask *why* you are trying to test for floating<br />
point equality rather than just a suitable proximity?</p>
<p>Have a play with this to see why comparing floating point numbers can<br />
be problematic:</p>
<p><a href="http://babbage.cs.qc.edu/IEEE-754/Decimal.html" rel="nofollow">http://babbage.cs.qc.edu/IEEE-754/Decimal.html</a></p>
<p>If you enter 0.1, you'll see the 32-bit representation is different<br />
for rounded vs non-rounded but if you enter 0.01 you'll see it is the<br />
same for rounded vs non-rounded (and neither are equal to 0.01 within<br />
the precision allowed by 32-bits). As you can imagine, lots of factors<br />
come into play when manipulating floating point numbers &#8211; how constant<br />
expressions are reduced, how optimization is performed on<br />
subexpressions&#8230;"</p>
<p>In my case I was able to change my code to test for suitable proximity. </p>
<p>(I also checked the Railo source and it doesn't use BigDecimal for floating point values)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Offner</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187528</link>
		<dc:creator>Michael Offner</dc:creator>
		<pubDate>Wed, 05 Aug 2009 07:12:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187528</guid>
		<description>this problem is the nature of java double values, because java is not a mathematical language.
for more details check out this blog 
http://epramono.blogspot.com/2005/01/double-vs-bigdecimal.html
or google 
double java &quot;not exactly&quot;</description>
		<content:encoded><![CDATA[<p>this problem is the nature of java double values, because java is not a mathematical language.<br />
for more details check out this blog<br />
<a href="http://epramono.blogspot.com/2005/01/double-vs-bigdecimal.html" rel="nofollow">http://epramono.blogspot.com/2005/01/double-vs-bigdecimal.html</a><br />
or google<br />
double java "not exactly"</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187517</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Wed, 05 Aug 2009 03:23:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187517</guid>
		<description>Fair enough.  I added the particular offending loop there in a comment just for easier reference.</description>
		<content:encoded><![CDATA[<p>Fair enough.  I added the particular offending loop there in a comment just for easier reference.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd Rafferty</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187514</link>
		<dc:creator>Todd Rafferty</dc:creator>
		<pubDate>Wed, 05 Aug 2009 02:56:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187514</guid>
		<description>Railo results:
67
67.2
67.4
67.6
67.8

67
67.2
67.4
67.6
67.8

-- At any rate, it should be there. Micha can reject it with a reason and people can do a search and read his reason.</description>
		<content:encoded><![CDATA[<p>Railo results:<br />
67<br />
67.2<br />
67.4<br />
67.6<br />
67.8</p>
<p>67<br />
67.2<br />
67.4<br />
67.6<br />
67.8</p>
<p>&#8211; At any rate, it should be there. Micha can reject it with a reason and people can do a search and read his reason.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: barneyb</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187510</link>
		<dc:creator>barneyb</dc:creator>
		<pubDate>Wed, 05 Aug 2009 02:04:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187510</guid>
		<description>Todd,

Did you confirm that Railo exhibits the issues in the same way as ColdFusion?  Though all things considered, I&#039;m not convinced it&#039;s something that should be fixed by the engine.  You can circumvent the problem with the explicit use of BigDecimal, but since those are java.lang.Numbers, implicit floating point correction could &quot;break&quot; very precise calculations with no recourse.  Ground to tread carefully to be sure on the side of the CFML engines, since it&#039;s not a bug per se, but an issue with the CFML language.</description>
		<content:encoded><![CDATA[<p>Todd,</p>
<p>Did you confirm that Railo exhibits the issues in the same way as ColdFusion?  Though all things considered, I'm not convinced it's something that should be fixed by the engine.  You can circumvent the problem with the explicit use of BigDecimal, but since those are java.lang.Numbers, implicit floating point correction could "break" very precise calculations with no recourse.  Ground to tread carefully to be sure on the side of the CFML engines, since it's not a bug per se, but an issue with the CFML language.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd Rafferty</title>
		<link>https://www.barneyb.com/barneyblog/2009/08/04/more-floating-point-madness/comment-page-1/#comment-187509</link>
		<dc:creator>Todd Rafferty</dc:creator>
		<pubDate>Wed, 05 Aug 2009 01:54:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.barneyb.com/barneyblog/?p=1038#comment-187509</guid>
		<description>Logged:
https://jira.jboss.org/jira/browse/RAILO-354</description>
		<content:encoded><![CDATA[<p>Logged:<br />
<a href="https://jira.jboss.org/jira/browse/RAILO-354" rel="nofollow">https://jira.jboss.org/jira/browse/RAILO-354</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
