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

2007-05-17 Thread Richard Lynch
On Wed, May 16, 2007 9:08 am, Brian Moon wrote:
 According to my memory of Please My Dear Aunt Sally these should be:

My memory has My Dear in equal priority, left to right...

This documentation would seem to bear that out:
http://us.php.net/manual/en/language.operators.php#language.operators.precedence

 -1/2*5 = -.1
 1/-2*5 = -.1
 1/2*-5 = -.1

Those are most definately all wrong. :-)

 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?

Yes.

The unary - operator buried in the third line that table is that
rule.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



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

2007-05-16 Thread Michael Wallner
[EMAIL PROTECTED] wrote:
  ID:   41401
  Updated by:   [EMAIL PROTECTED]
  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)



Regards,
-- 
Michael

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



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

2007-05-16 Thread Richard Quadling

On 16/05/07, Uwe Schindler [EMAIL PROTECTED] wrote:

 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)

They should all give -2.5! But I think normal programmers will use braces
in such situations...

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php




If you use variables, then this works fine ...

php -r $a = 1; $b = -2; $c = 5; var_dump($a/$b*$c);
float(-2.5)



--
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
Standing on the shoulders of some very clever giants!

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



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

2007-05-16 Thread Brian Moon

Michael Wallner wrote:

[EMAIL PROTECTED] wrote:

 ID:   41401
 Updated by:   [EMAIL PROTECTED]
 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?


--

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



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

2007-05-16 Thread Brian Moon

Brian Moon wrote:

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?


My memory was corrected off list.  Thanks.  Stupid teachers and their 
mnemonics.


But, still, PHP is wrong on 1/-2*5 no?

--

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



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

2007-05-16 Thread Matt Wilmas
Hi Richard,

- Original Message - 
From: Richard Quadling
Sent: Wednesday, May 16, 2007

[...]
 If you use variables, then this works fine ...

 php -r $a = 1; $b = -2; $c = 5; var_dump($a/$b*$c);
 float(-2.5)

Certainly. :-)  The problem seems to be the parser is acting weird as far as
precedence goes with 1/-2*5.


Matt

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



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

2007-05-16 Thread Richard Quadling

On 16/05/07, Brian Moon [EMAIL PROTECTED] wrote:

Michael Wallner wrote:
 [EMAIL PROTECTED] wrote:
  ID:   41401
  Updated by:   [EMAIL PROTECTED]
  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=ZEND002498r=213474731
Standing on the shoulders of some very clever giants!

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



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

2007-05-16 Thread Michael Wallner
Michael Wallner wrote:

 Should all these three examples give the same result?
^ n't


 $ php -r 'var_dump(-1/2*5, 1/-2*5, 1/2*-5);'
 float(-2.5)
 float(-0.1)
 float(-2.5)

Sorry,
-- 
Michael

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php