Re: Re: #41401 [Opn->Bgs]: Order of Operations error on divide by negative

From: Date: Wed, 16 May 2007 14:25:59 +0000
Subject: Re: Re: #41401 [Opn->Bgs]: Order of Operations error on divide by negative
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-29470@lists.php.net to get a copy of this message
On 16/05/07, Brian Moon <brianm@dealnews.com> wrote:
Michael Wallner wrote: tony2001@php.net wrote:
 ID:               41401
 Updated by:       tony2001@php.net
 Reported By:      drlippman at yahoo dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Math related
Operating System: Windows, Linux
 PHP Version:      4.4.7
New Comment: [2007-05-15 15:44:07] drlippman at yahoo dot com Description: ------------ Left-to-right order of operations does not appear to be honored when dividing by a negative Reproduce code: --------------- 1/-2*5 Expected result: ---------------- -2.5 Actual result: -------------- -.1
Should all these three examples give the same result? $ php -r 'var_dump(-1/2*5, 1/-2*5, 1/2*-5);' float(-2.5) float(-0.1) float(-2.5) According to my memory of Please My Dear Aunt Sally these should be: -1/2*5 = -.1 1/-2*5 = -.1 1/2*-5 = -.1 So, that is bad if PHP answers that way. Someone please correct me if my memory is wrong. Is there some rule that negative values should be done first before positive values?
I'm in the UK and I was taught (over 35 years ago at least) about BODMAS Brackets Orders Division Multiplication Addition Subtraction. http://en.wikipedia.org/wiki/BODMAS
-- Brian Moon Senior Developer ------------------------------ http://dealnews.com/ It's good to be cheap =) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!"

« previous php.internals (#29470) next »