Math Algorithm Bug

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).
AuthorTopic: Math Algorithm Bug
Apprentice
Member # 4258
Profile #0
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.
Posts: 28 | Registered: Wednesday, April 14 2004 07:00
Post Navel Trauma ^_^
Member # 67
Profile Homepage #1
I bet it's doing 24 - (21 + 1) and 1 + (24 - 21).
Still a bug, but that'll be why.

When precedence matters, you should probably use brackets just to be on the safe side.

--------------------
Barcoorah: I even did it to a big dorset ram.

New Mac BoE
Posts: 1798 | Registered: Thursday, October 4 2001 07:00
Board Administrator
Member # 1
Profile Homepage #2
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

--------------------
Official Board Admin
spidweb@spiderwebsoftware.com
Posts: 960 | Registered: Tuesday, September 18 2001 07:00