Rounding Error Issues of Floating Arithmetic – Arduino

///Rounding Error Issues of Floating Arithmetic – Arduino

Rounding Error Issues of Floating Arithmetic – Arduino

There is an issue with the previously shown fade mathematics which only appear on the Arduino. What seemed strange at first soon became clear. Micro-controllers are inherently more  comfortable 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 arithmetic. The reason behind this rounding error is a cumulative error build up by recalculating repeatedly with an already error vulnerable result.

A new method was created whereby this cumulative buildup 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.

Some maths:

Step Size = ƒ

We have Xi and Xf      ƒ = (Xf – Xi)/t

where t is fade time

Previously we were doing this:

Current Value =

[ (Xi + ƒ)  + ƒ ]

We can see here that any previous rounding error gets re-included in this calculation.

Simple alternative method

Current Value = Xi + n . ƒ

By |2016-11-05T11:17:47+00:00February 17th, 2011|Lightive Project|0 Comments

About the Author:

A PhD in Electronic Engineering. A love for photography (www.islou.co.uk). An interest in tinkering, electronics and design. (www.louisc.co.uk).

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.