I have an I2C device that wants two inputs: a denominator and a numerator. Both are written to separate addresses, so no actual calculation (numerator/denominator
) is done. The problem with this is that a divide by zero could occur on the I2C device, so a divide by zero error needs to be checked for. Ideally, exactly the same thing would happen if the dividing were done by the java code.
At the moment, I've bodged an unused variable that does the division, but I'm worried it'll get optimized out:
public void setKp(int numerator, int divisor)
{
int zeroCheck = numerator / divisor;
//... doesn't use zeroCheck
}
Surely there's a better way!