Jump to content

Math Algorithm Bug


Gorvin
 Share

Recommended Posts

I just found a strange little bug in the math algorithm...

I tested these 2 lines of code:

 

print_num(24 - 21 + 1);

print_num(1 + 24 - 21);

 

They *should* both produce a result of 4, yet the first line subtracts the 1 instead of adding it and produces a result of 2. The second line works fine however.

Link to comment
Share on other sites

It's because subtraction mistakenly has equal precedence with addition, and operations are done from right to left.

 

The first thing will be fixed, but operations will continue to be right to left.

 

- Jeff

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...