<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Rounding error in simple addition</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7b32dc4edf/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7b32dc4edf/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/7b32dc4edf/</id><updated>2024-05-25T23:42:44.831000Z</updated><subtitle>Recent posts to Rounding error in simple addition</subtitle><entry><title>Rounding error in simple addition</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7b32dc4edf/?limit=25#af8a" rel="alternate"/><published>2024-05-25T23:42:44.831000Z</published><updated>2024-05-25T23:42:44.831000Z</updated><author><name>dhumphries</name><uri>https://forge.codesys.com/u/dhumphries/</uri></author><id>https://forge.codesys.com295e26d907dce24c302935da9b7a6c1a312cc9ec</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks for the response, as I've thought about this problem over the last month I began to suspect this was a problem with not being able to exactly represent .1 as a 32 bit binary number.  I think I've found a work around by making the number an integer, then dividing it by 10 and storing that value as a floating point number.  There is still an issue with the value not being exact somewhere in the 8th or 9th decimal place, but because I'm incrementing an integer value then dividing it, the error doesn't compound.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Rounding error in simple addition</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7b32dc4edf/?limit=25#30a0" rel="alternate"/><published>2024-05-24T11:10:57.739000Z</published><updated>2024-05-24T11:10:57.739000Z</updated><author><name>ndzied2</name><uri>https://forge.codesys.com/u/ndzied2/</uri></author><id>https://forge.codesys.com6262621a9e7998ae2348b9dfe1698fe520707ecd</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;This is a consequence of how computers store floating point numbers. 0.1 cannot be exactly represented in a computer. This is not a CoDeSys thing. Here is a link to a converter to show you the exact value that is represented when you use a REAL data type (which is a 32 bit float).&lt;br/&gt;
&lt;a href="https://baseconvert.com/ieee-754-floating-point" rel="nofollow"&gt;https://baseconvert.com/ieee-754-floating-point&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you really need to keep track of 0.1 increments. use INT OR DINT and then add 1 each time and assume that there is one decimal place. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Rounding error in simple addition</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7b32dc4edf/?limit=25#b84e" rel="alternate"/><published>2024-05-24T11:10:54.376000Z</published><updated>2024-05-24T11:10:54.376000Z</updated><author><name>ndzied2</name><uri>https://forge.codesys.com/u/ndzied2/</uri></author><id>https://forge.codesys.com28326cef41f5162403d2354360a51a133a2d1803</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;This is a consequence of how computers store floating point numbers. 0.1 cannot be exactly represented in a computer. This is not a CoDeSys thing. Here is a link to a converter to show you the exact value that is represented when you use a REAL data type (which is a 32 bit float).&lt;br/&gt;
&lt;a href="https://baseconvert.com/ieee-754-floating-point" rel="nofollow"&gt;https://baseconvert.com/ieee-754-floating-point&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you really need to keep track of 0.1 increments. use INT OR DINT and then add 1 each time and assume that there is one decimal place. &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Rounding error in simple addition</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7b32dc4edf/?limit=25#8caa" rel="alternate"/><published>2024-05-24T01:28:01.773000Z</published><updated>2024-05-24T01:28:01.773000Z</updated><author><name>dhumphries</name><uri>https://forge.codesys.com/u/dhumphries/</uri></author><id>https://forge.codesys.comdad5f9b9b380b384ebebebf60db01b0ae9adc828</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Bump&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Rounding error in simple addition</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7b32dc4edf/?limit=25#1710" rel="alternate"/><published>2024-04-27T04:16:35.848000Z</published><updated>2024-04-27T04:16:35.848000Z</updated><author><name>dhumphries</name><uri>https://forge.codesys.com/u/dhumphries/</uri></author><id>https://forge.codesys.come5d325703c9f6bb15ea5f9a876a7dae6661b60ee</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have discovered a rounding error, either in Codesys or in my understanding of numbers.  The attached ladder shows that when the up button is pressed the number increases by 0.1, when the down button is pressed number decreases by 0.1, after several button presses the number isn't equally divisible by 0.1.&lt;/p&gt;
&lt;p&gt;Have I discovered a bug or am I doing something wrong?&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>