ios - Why do brackets mess up this math in objective-c? -
why 2 calculations have differing results? xcode 6.1.
(lldb) print newbounds.size.height (cgfloat) $0 = 446.5 (lldb) print newbounds.size.height * 6/4 (double) $1 = 669.75 (lldb) print newbounds.size.height * (6/4) (double) $2 = 446.5
it's integer math , usual rules promotion of types.
height * 6/4 == (height * (double)6) / (double)4 == (height * 6.0) / 4.0
whereas:
height * (6/4) == height * (double)(1) == height * 1.0
since 6/4 == 1
, parentheses force evaluated first before promoting double
.
this same behaviour in c, c++, objective-c, et al, shouldn't surprised see in debugger too.
Comments
Post a Comment