Getting mixed results with pow()


hi

i understand pow takes 2 floats , returns double , afaik floating point arithmetic not exact. don't why i'm getting mixed results same input, when i'm using pow in loop. see here:

code: [select]

    myglcd.setfont(bigfont);
    myglcd.printnumi(pow(10,2),0,220); //[100]
    delay(1000);
    myglcd.clrscr();
    (byte i=0;i<2;i++){ //1000, [100]
      myglcd.printnumi(pow(10,3-i),0,220);
      delay(1000);
      myglcd.clrscr();
    }
    (byte i=0;i<3;i++){ //999, [99]!!!, 10
      myglcd.printnumi(pow(10,3-i),0,220);
      delay(1000);
      myglcd.clrscr();
    }
    (byte i=0;i<3;i++){ //1000, [100], 10
      myglcd.printnumi(round(pow(10,3-i)),0,220);
      delay(1000);
      myglcd.clrscr();
    }


i guess i'm getting 99.999... works enough after rounding, point why getting when input same? feels if pow depended on timer something... can explain it, please?

quote
but point why getting when input same?
we can't see getting. print values serial monitor, not lcd. know, code prints lcd flawed.

there no reason use pow() integer arithmetic.


Arduino Forum > Using Arduino > Programming Questions > Getting mixed results with pow()


arduino

Comments