问题
I'm just wondering, because the app I built does a pretty long equation, and the result is a different than when it's done on an Excel spreadsheet, where I got the equation. The difference gets higher the higher the input numbers are. Here is the equation that I entered in xcode:360 * num1 * num3 * (1 - powf(14.9 / num1, 0.286))
(num1 and num3 are the input numbers).
Here is the Excel calculation:=360*R9*R11*(1-((R10/R9)^0.286))
(R9
is equal to num1
, and R11
is equal to num3
and R10
is 14.9)
I don't see a difference in the equations, but if you do, please point it out. My quess it one of the two (probably the ob-c one) is doing something different than what I expected.
回答1:
Yes. Objective-C is a superset of C.
So all the features that C has, Objective-C has as well.
360 * num1 * num3 * (1 - powf(14.9 / num1, 0.286)) (num1 and num3 are the input numbers)
A * num3 * (1 - powf(14.9 / num1, 0.286))
B * (1 - powf(14.9 / num1, 0.286))
B * (1 - powf(C, 0.286))
B * (1 - D)
B * (E)
F
And just for information, BEDMAS is not fully followed. If D & M are there at same level, the left most will be evaluated first, and so is the rule for A & S. However this does not look big deal, but when it comes to truncation and rounding with decimal numbers it creates a big problem.
a * b / c is calculated as "(a*b) / c"
whereas
a / b * c is calculated as "(a/b) * c"
来源:https://stackoverflow.com/questions/14074955/does-objective-c-follow-the-order-of-operations-bedmas