By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,233 Members | 1,806 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,233 IT Pros & Developers. It's quick & easy.

order of operations with division and multiplication

P: n/a
The following lines were tried:

x1 = (-b + sqrt(pow(b,2)-(4*a*c))) /(2*a);

x1 = (-b + sqrt(pow(b,2)-(4*a*c))) / 2*a;
I noticed that the last parentheses were optional and didn't change
anything.
Although if I mean 1/(2*5)=0.1 then 1/2*5=2.5 is not the same. What
is the difference?

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Tim923 wrote:
The following lines were tried:

x1 = (-b + sqrt(pow(b,2)-(4*a*c))) /(2*a);

x1 = (-b + sqrt(pow(b,2)-(4*a*c))) / 2*a;
I noticed that the last parentheses were optional and didn't change
anything.
Although if I mean 1/(2*5)=0.1 then 1/2*5=2.5 is not the same. What
is the difference?


It's not order, but grouping. That is, you have to be sure that each
operation gets applied to the correct operands. Generally speaking, math
operators group from left to right, so a/b*c says that a should be
divided by b, and the result multiplied by c. To change this grouping,
add parentheses: a/(b*c).

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #2

P: n/a
It should matter, and does for me. Sure you tried it with something
other than a=1?

Jul 23 '05 #3

P: n/a
Tim923 wrote:
Although if I mean 1/(2*5)=0.1 then 1/2*5=2.5 is not the same. What
is the difference?


The Rank of both operators / and * is the same in the second example,
but the associativity in this case is from left to right. That means
that operator 1/2 is calculated first, after this 1/2 is multiplied by 5.

Due to higher Rank of "()" 2*5 is calculated before the division in the
first example.
Jul 23 '05 #4

P: n/a
Evan wrote:
It should matter, and does for me. Sure you tried it with something
other than a=1?


That's it. I think a was 1.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.