Interesting to see some of my code back
Some Arduino floating points points:
- the Arduino has only 7 digits of precision, the compiler will take care of rounding
- the compiler accepts E notation in float constants, which removes unneeded pow(10, n) from your code
- a fifth order polynome with integer powers can speed up by a big factor by decomposing it using only 5 multiplies and 5 additions.
long val = 420;
f = 1.354026784*pow(10,-8)*pow(val,5) //pow(10,-8) raises 1.354026784 to the 10-8
// removing pow() completely
f = 1.354026784E-8* val*val*val*val*val - 2.559722383E-5* val*val*val*val + 1.92917182E-2 * val*val*val - 7.24448384 * val*val + 1356.112407*val - 101259.7822;
// minimize math
f = (((( 1.354026784E-8 * val - 2.559722383E-5 ) * val + 1.92917182E-2 ) * val - 7.24448384 ) * val + 1356.112407) * val - 101259.7822;
Note that method 2 and 3 which uses less operations already differ in the 4th digit, so calculating this with more than 5 digits is speculative at best.
This is caused by the fact that all the partial sums ( a.pow(b,n) ) are in the same order of magnitude 10^5..10^6 and their sum is 2 to 3 orders of magnitude lower.
(you're losing significant bits here)
BTW according to Excel the "right" value == 116.935898400974 so simplifying the math does make it worse this time.
Excel snippet (,'s are due to localization)
coefficient 420^n partial result
1,354026784000000E-08 1,306912320000000E+13 1,769594285619580E+05
-2,559722383000000E-05 3,111696000000000E+10 -7,965077900291570E+05
1,929171820000000E-02 7,408800000000000E+07 1,429284818001600E+06
-7,244483840000000E+00 1,764000000000000E+05 -1,277926949376000E+06
1,356112407000000E+03 4,200000000000000E+02 5,695672109400000E+05
-1,012597822000000E+05 1,000000000000000E+00 -1,012597822000000E+05
sum = 1,169358984009740E+02