www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7268] New: Incorrect sign when raising negative number to even power.

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

           Summary: Incorrect sign when raising negative number to even
                    power.
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: mail.mantis.88 gmail.com



dmd 2.057, windows
Raising negative number to even power results in a negative number, e.g.:

static assert( (-10 ^^ 2) != (-10 * -10) ); //pass
static assert( (-10 ^^ 2) == (-10 * -10) ); //Error: static assert  (-100 ==
100) is false

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 10 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7268


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID



This is correct.
http://d-programming-language.org/expression.html#UnaryExpression

From priority of operators, (-10 ^^ 2) is translated to (-(10^^2)), so the
result is -(100) == -100.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 12 2012