ShoeLace1291 Posted November 21, 2008 Share Posted November 21, 2008 Does PHP use the order of operations crap in mathematics? You know the old please excuse my dear aunt sally crap. I'm trying to incorporate a formula that my friend and I came up with for a league system that figures out what amount of experience each team gets after a match. My question is that what syntax would I need to use for a formula like this: [(5/L)W] + [N+(W-L)] = x Quote Link to comment Share on other sites More sharing options...
corbin Posted November 21, 2008 Share Posted November 21, 2008 Yes it does. And the order of operations is not crap. It has a purpose, and ignorance of it does not constitute it being crap ;p. (Well maybe instead of ignorance, laziness would've been better suited there.) $x = ((5/$l)*$w) + ($n+($w-l)); Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 21, 2008 Share Posted November 21, 2008 Stick with ignorance corbin. And I guess I should TRY to be productive in my post as well... (5/$l*$w) + ($n+$w-l) Quote Link to comment Share on other sites More sharing options...
corbin Posted November 21, 2008 Share Posted November 21, 2008 I usually go for readability, but yeah genericnumber1's is valid too. And actually better since it's like .00000000001 seconds faster ;p. You actually used the order of operations hehe. I'm an over-grouper. Calculators have trained me that way x.x. Should've condensed it though. I was just lazy. Ironic, eh? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 21, 2008 Share Posted November 21, 2008 Hey, in that .00000000001 seconds, you could have considered considering thinking about something. I do the same thing with calculators, corbin. I hate thinking about the order of operations involved (I'm using a calculator, I shouldn't have to think, dagnabbit!) so I just group everything with parenthesis. Quote Link to comment Share on other sites More sharing options...
corbin Posted November 21, 2008 Share Posted November 21, 2008 I've had people look at math problems I've done before and tell me they're wrong because the order of operations is assumed lol. On paper I don't use grouping symbols except when needed, but I find on a computer, since everything is typically written on one line (as in no division symbols except for / and so on), it's easier to comprehend with a crap load of parenthesis. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted November 21, 2008 Share Posted November 21, 2008 The only time I find myself using tons of parenthesis in programming are those confusing if/then conditionals everyone loves if ((something || something) && (something && (something || something)) { of course I try to avoid them when neccessary, but worrying about the fact that && is higher precedence than || is just a pain... so I parenthesis up. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted November 21, 2008 Share Posted November 21, 2008 Drop all this grouping and brackets stuff, and even order or precedence for operators.... use RPN Once you get accustomed to using it, it's totally intuitive and easy Quote Link to comment Share on other sites More sharing options...
corbin Posted November 21, 2008 Share Posted November 21, 2008 "of course I try to avoid them when neccessary, but worrying about the fact that && is higher precedence than || is just a pain... so I parenthesis up." && and || aren't the same order? I think they're both just parsed from left to right.... Quote Link to comment Share on other sites More sharing options...
Mchl Posted November 21, 2008 Share Posted November 21, 2008 && and || aren't the same order? I think they're both just parsed from left to right.... They're not just as they are not in boolean logic. Difficult to remember? && is multiplication, and || is summing.... And * has higher precedence than + Quote Link to comment Share on other sites More sharing options...
corbin Posted November 21, 2008 Share Posted November 21, 2008 Hrmmm learned something ;p. I actually found that page after reading your post, but then I forgot about this thread lol. Edit: Things like C:\Users\Corbin>php -r "var_dump(false && false || true && false);" bool(false) Were why I had assumed they have the same order of operations. But, either way would make sense in that specific context. I guess I shouldn't assume ;p. Quote Link to comment Share on other sites More sharing options...
mcs295 Posted November 22, 2008 Share Posted November 22, 2008 hello sir, i have one question regarding mathematic operators that i have three pages and all paged having radio button values. one page having only one value so it is very simple to move this value to next page. but second pages having two radio buttons values plus previous page value. please help me to fix out our problem thanks Quote Link to comment Share on other sites More sharing options...
corbin Posted November 22, 2008 Share Posted November 22, 2008 Hidden fields would be the easiest way. Oh, by the way, people generally frown on thread hijacking, even though this thread was most likely dead. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.