Should I use floating-point or integer math for sensor values.


time more specific.


my actual code on 2000 lines of object-oriented goodness, i'll give simplified version of i'm doing.

code: [select]

uint64_t accumulator; //the question: should use large integer this, or can use float/double?
uint32_t numsamples;
float actualvalue;

void accumulatevalues()
{
accumulator += readtcvalue()*1000; //this value floating-point, multiply 1000 keep 3 decimal places.
numsamples++
}

void applyvalues()
{
actualvalue = accumulator / numsamples / 1000; //divide 1000 out multiplied earlier
numsamples = 0;
accumulator = 0;
}

void loop()
{
currenttime = millis();

while (millis() - currenttime < 10000) // loops fast can until 10s has passed
{
accumulatevalues(); //accumulates sensor value samples
}

applyvalues(); //grabs average of said samples , resets accumulator , sample counter
serial.println(actualvalue);
}


so right accumulate values integer value. i'm wondering if float/double able work in scenario. way, don't have multiply 1000 , divide out later. concern addition screwy on value exponent keeps changing. like, happens if add 2 floating-point value of 1.00000000000x10^15, add if doesn't register in variable? or data lost?

sorry if bit of roughly-asked question.

no idea, beauty of software development can test ;)


Arduino Forum > Using Arduino > Programming Questions > Should I use floating-point or integer math for sensor values.


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts