{"id":381,"date":"2011-02-17T18:36:57","date_gmt":"2011-02-17T18:36:57","guid":{"rendered":"http:\/\/louisc.co.uk\/FYP\/?p=381"},"modified":"2016-11-05T11:17:47","modified_gmt":"2016-11-05T11:17:47","slug":"rounding-error-issues-of-floating-arithmetic","status":"publish","type":"post","link":"https:\/\/louisc.co.uk\/?p=381","title":{"rendered":"Rounding Error Issues of Floating Arithmetic &#8211; Arduino"},"content":{"rendered":"<p>There is an issue with the previously shown fade mathematics which only appear on the Arduino. What seemed strange at first soon became clear.\u00a0Micro-controllers are inherently more \u00a0comfortable performing integer mathematics over floating point. After analysing the results of the equations which were output to the computer via serial, the issue became clear. Rounding error of floating point\u00a0arithmetic. The reason behind this rounding error is a cumulative error build up by recalculating repeatedly with an already error\u00a0vulnerable\u00a0result.<\/p>\n<p>A new method was created whereby this\u00a0cumulative\u00a0buildup was combated by tracking which iteration of a fade the system was currently on and using that to calculate the current value. Pretty simple really.<\/p>\n<h2>Some maths:<\/h2>\n<p>Step Size =\u00a0\u0192<\/p>\n<p>We have Xi and Xf \u00a0 \u00a0 \u00a0\u0192 = (Xf &#8211; Xi)\/t<\/p>\n<p>where t is fade time<\/p>\n<h3>Previously we were doing this:<\/h3>\n<p>Current Value = <div class=\"fusion-fullwidth fullwidth-box hundred-percent-fullwidth non-hundred-percent-height-scrolling\"  style='background-color: rgba(255,255,255,0);background-position: center center;background-repeat: no-repeat;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;'><div class=\"fusion-builder-row fusion-row \"><div  class=\"fusion-layout-column fusion_builder_column fusion_builder_column_1_1  fusion-one-full fusion-column-first fusion-column-last fusion-column-no-min-height 1_1\"  style='margin-top:0px;margin-bottom:0px;'>\n\t\t\t\t\t<div class=\"fusion-column-wrapper\" style=\"background-position:left top;background-repeat:no-repeat;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover;background-size:cover;\"  data-bg-url=\"\">\n\t\t\t\t\t\t[ (Xi +\u00a0\u0192) \u00a0+\u00a0\u0192 ]\n<p>We can see here that any previous rounding error gets\u00a0re-included\u00a0in this calculation.<\/p>\n<h3>Simple alternative\u00a0method<\/h3>\n<p>Current Value = Xi + n .\u00a0\u0192<div class=\"fusion-clearfix\"><\/div>\n\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div><\/div><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There is an issue with the previously shown fade mathematics which only appear on the Arduino. What seemed strange at first soon became clear.\u00a0Micro-controllers are inherently more \u00a0comfortable performing integer mathematics over floating point. After analysing the results of the equations which were output to the computer via serial, the issue became clear. Rounding error of floating point\u00a0arithmetic. The reason behind this rounding error is a cumulative error build up by recalculating repeatedly with an already error\u00a0vulnerable\u00a0result. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[32],"tags":[34,35,42],"class_list":["post-381","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lightive-reactive-lighting-system","tag-arduino","tag-atmel","tag-c"],"_links":{"self":[{"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=381"}],"version-history":[{"count":14,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":2722,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/381\/revisions\/2722"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=\/wp\/v2\/media\/473"}],"wp:attachment":[{"href":"https:\/\/louisc.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/louisc.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}