I have the following double calculation in Java:
double C1 = some value; // It's always an integer
double C2 = some value; // It's always integer, and C2 >= C1
double S = some value; // It's always 0 < S <= 1
double carry = some value; // It's always 0 <= carry < 1
double rate = ((C1/C2)/S);
double C3 = Math.floor( (rate * S * C2) + carry );
Now, if we did not lose precision, C3 == C1
would be true. But since we lose precision, will C3
and C1
still always be equal?
If they would not always be equal, if I have C1
, C2
, S
, and C3
, how could I modify the rate
to make sure after calculation C3
would be equal to C1
?
Note: unfortunately using BigDecimal is not an option.