float actualDuration = rando/denom + 1;
NSLog(@"%f", actualDuration);
I'm not 100% confident in the casting rules, but as far as I experienced it what happens is that rando
and denom
being integers and integer division is used, resulting in an integer value.
Therefore you need to cast at least the denominator to float
but it's better to cast them both, as well as using the standard float
notation for constant values (1.0f
):
float actualDuration = (float)rando / (float)denom + 1.0f;
NSLog(@"%f", actualDuration);
Personally I tend to cast all integer values to float/double/CGFloat when using them in calculations just so that none of the casting rule issues can creep in.