www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5174] New: -x ^^ 0 returns -1

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5174

           Summary: -x ^^ 0 returns -1
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ibuclaw ubuntu.com


--- Comment #0 from Iain Buclaw <ibuclaw ubuntu.com> 2010-11-05 13:14:14 PDT ---
Code:
import std.stdio;
import std.math;

void main(string[] args)
{
    writefln("test:   %s%6s", "pow()", "^^");

    writefln("-3^^0:  %s%10s", pow(-3, 0), -3^^0);
    writefln("-2^^0:  %s%10s", pow(-2, 0), -2^^0);
    writefln("-1^^0:  %s%10s", pow(-1, 0), -1^^0);
    writefln(" 0^^0:  %s%10s", pow( 0, 0),  0^^0);
    writefln(" 1^^0:  %s%10s", pow( 1, 0),  1^^0);
    writefln(" 2^^0:  %s%10s", pow( 2, 0),  2^^0);
    writefln(" 3^^0:  %s%10s", pow( 3, 0),  3^^0);
}


Outputs:
test:   pow()    ^^
-3^^0:  1        -1
-2^^0:  1        -1
-1^^0:  1        -1
 0^^0:  1         1
 1^^0:  1         1
 2^^0:  1         1
 3^^0:  1         1



Note that zero, and positive to the power of 0 match the return value of pow().
But negative numbers to the power of 0 don't.

Marking as major because this could cause confusion.

Regards

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 05 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5174


Iain Buclaw <ibuclaw ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P4
             Status|NEW                         |RESOLVED
                 CC|                            |ibuclaw ubuntu.com
         Resolution|                            |FIXED
           Severity|major                       |minor


--- Comment #1 from Iain Buclaw <ibuclaw ubuntu.com> 2010-11-05 13:26:12 PDT ---
Hmm... actually, I think not now.

Part of the confusion was that it gets parsed down like so:

=>  -3 ^^ 0
=>  -(3 ^^ 0)
=>  -(1)


When I expected it to be:

=>  -3 ^^ 0
=>  ((-3) ^^ 0)
=>  (1)


I'll assume that this behaviour is normal, sorry for the noise. :~)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5174


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #2 from bearophile_hugs eml.cc 2010-11-05 14:03:12 PDT ---
I am not saying this is bad or good, but I want to show what Python 2.6.6 does
(the same as D, it seems):

 -1**0
-1
 pow(-1, 0)
1 (I recall some threads about this behaviour in the Python newsgroups, some person was not happy of it). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 05 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5174


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla kyllingen.net
         Resolution|FIXED                       |INVALID


--- Comment #3 from Lars T. Kyllingstad <bugzilla kyllingen.net> 2010-11-08
02:14:20 PST ---
The negation and exponentiation operators have the same relative precedence in
D as in mathematics.  I would be extremely surprised if I wrote -2^^2 and got
4.

Correcting the resolution of this bug, since nothing was fixed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2010