Using the ceilf
operator fixed it for me:
float x1 = ceilf(ceilf(ceilf(100*1.0f)*1.0f)*1.1f);
NSLog(@"%f",x1); // 110
Pergunta
The following code is returning an unexpected (and wrong value).
x1 = ceil(ceil(ceil(100*1.0f)*1.0f)*1.1f);
It is returning 111 not 110. I am aware that multiplying a number by 1 is pointless, but those 1's are not always ones. When they are other values the function works as expected.
Solução
Using the ceilf
operator fixed it for me:
float x1 = ceilf(ceilf(ceilf(100*1.0f)*1.0f)*1.1f);
NSLog(@"%f",x1); // 110
Outras dicas
This is a matter of floating point errors. 1.1f is probably really something like 1.100056778.
This means that 100 * 1.100056778 = 110.0056778. And the ceil
of that number is 111.