Floating Point arithmetic does not work?
Heater.
Posts: 21,230
From time to time a little debate starts up here about the use of Floating Point arithmetic on the Propeller. Perhaps someone someone posts a question on if or how floating point math can be done on the Propeller (Or indeed any other MCU).
Often such questions arise because someone simply cannot fathom how to do something simple like add, subtract, multiply, divide non-integer number numbers.
Or they just can't be bothering to worry about over flows and under flows.
Or they might be trying something a bit harder involving trig functions.or logs.
Often some bright sparks (Like me:)) Jumps up and proclaims "If you think you need floating point to solve your problem then you don't understand your problem". That being what a boss of mine used to preach back in the 1980's to us young software guys when we got stuck on problems on minicomputers with no float support and no time to let the compiler do it in software.
Others will chime in and point out that taking the easy way out with floating point is quite OK if you have time and space available.
I'm actually happy to "float or not" depending on the situation as long as you are aware of the possible pitfalls.
Anyway to the point: The weather forecasting community has recently discovered they cannot trust their weather models to produce the same results from the same input using the same software when run on different super computers. Basically down to the way floating point works on different machines.
See here: http://journals.ametsoc.org/doi/abs/10.1175/MWR-D-12-00352.1
In light of that result I'm upgrading my bosses statement:
"If you think you need floating point to solve you problem then you don't understand your problem. If you find you do need floating point to solve your problem then you definitely no longer understand your problem"
P.S. This property of weather models to give very different results in the face of very small errors in input has been known since the 1970's It's what gave rise to chaos theory. If you think of the output of every iteration of such a model as an input to the next iteration then these rounding errors they are reporting are the same effect and I don't see why anyone is surprised.
Often such questions arise because someone simply cannot fathom how to do something simple like add, subtract, multiply, divide non-integer number numbers.
Or they just can't be bothering to worry about over flows and under flows.
Or they might be trying something a bit harder involving trig functions.or logs.
Often some bright sparks (Like me:)) Jumps up and proclaims "If you think you need floating point to solve your problem then you don't understand your problem". That being what a boss of mine used to preach back in the 1980's to us young software guys when we got stuck on problems on minicomputers with no float support and no time to let the compiler do it in software.
Others will chime in and point out that taking the easy way out with floating point is quite OK if you have time and space available.
I'm actually happy to "float or not" depending on the situation as long as you are aware of the possible pitfalls.
Anyway to the point: The weather forecasting community has recently discovered they cannot trust their weather models to produce the same results from the same input using the same software when run on different super computers. Basically down to the way floating point works on different machines.
See here: http://journals.ametsoc.org/doi/abs/10.1175/MWR-D-12-00352.1
In light of that result I'm upgrading my bosses statement:
"If you think you need floating point to solve you problem then you don't understand your problem. If you find you do need floating point to solve your problem then you definitely no longer understand your problem"
P.S. This property of weather models to give very different results in the face of very small errors in input has been known since the 1970's It's what gave rise to chaos theory. If you think of the output of every iteration of such a model as an input to the next iteration then these rounding errors they are reporting are the same effect and I don't see why anyone is surprised.
Comments
However perhaps my upgraded bosses statement is not forceful enough.
I am going to assume that these weather forecasting models have been put together of a long period of time by some of the finest minds in mathematics and computer science we have. However the discrepancies they found when running the same code with the same inputs on different machines seems to be a newsworthy surprise to them. Seems they did not understand that this might happen.
So my stronger statement might be:
"If you think you need floating point to solve you problem then you don't understand your problem. If you find you do need floating point to solve your problem then your problem is no longer understandable".
Aside: One of the most reported bugs in JavaScript run times is along the lines of "0.1 + 0.2 == 0.3 yields false." Which clearly shows that those who jump into floating point without understanding what it is can get very confused and surprised and can easily create broken software.
I bet it should be:
0-256 into 0 to 100% where 256 doesn't happen therefore 100% is never happens.
So the resultant math is:
* 25 / 64
Duane J