Thread overview
[Issue 7006] std.math.pow (integral, integral) crashes on negative exponents
Oct 20, 2018
Cristian Creteanu
Dec 15, 2019
berni44
Dec 15, 2019
timon.gehr@gmx.ch
Dec 15, 2019
berni44
Dec 16, 2019
Dlang Bot
Dec 17, 2019
timon.gehr@gmx.ch
Jan 03, 2020
Dlang Bot
October 15, 2016
https://issues.dlang.org/show_bug.cgi?id=7006

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |bootcamp
                 CC|                            |andrei@erdani.com

--
October 20, 2018
https://issues.dlang.org/show_bug.cgi?id=7006

Cristian Creteanu <cristiancreteanu06@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |cristiancreteanu06@gmail.co
                   |                            |m

--- Comment #5 from Cristian Creteanu <cristiancreteanu06@gmail.com> ---
I provided a fix for the issue. However, I noticed that the return type of the function is an integer, which will make it impossible to have results different from 0 or 1 for negative exponents (2 to -2 is 0.5, but pow will return 0; 1 will be returned for powers of 1, of course). I believe that pow, no matter the arguments that are provided to it, should always return a floating point number.

--
December 15, 2019
https://issues.dlang.org/show_bug.cgi?id=7006

berni44 <bugzilla@d-ecke.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@d-ecke.de
         Resolution|---                         |WONTFIX

--- Comment #6 from berni44 <bugzilla@d-ecke.de> ---
(In reply to Cristian Creteanu from comment #5)
> I believe that
> pow, no matter the arguments that are provided to it, should always return a
> floating point number.

That would mean pow(4294967290UL,2) == 18446744022169944064 instead of the correct 18446744022169944100...

If you really need negative powers of integeres, you should cast to floating point before using pow.

--
December 15, 2019
https://issues.dlang.org/show_bug.cgi?id=7006

timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WONTFIX                     |---

--
December 15, 2019
https://issues.dlang.org/show_bug.cgi?id=7006

--- Comment #7 from berni44 <bugzilla@d-ecke.de> ---
I started some discussion about this in the forum:

https://forum.dlang.org/thread/ppmpassriwdohsipkeiy@forum.dlang.org

--
December 16, 2019
https://issues.dlang.org/show_bug.cgi?id=7006

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #8 from Dlang Bot <dlang-bot@dlang.rocks> ---
@berni44 created dlang/phobos pull request #7322 "Fix Issue 7006 - std.math.pow (integral, integral) crashes on negative exponents" fixing this issue:

- Fix Issue 7006 - std.math.pow (integral, integral) crashes on negative
exponents

https://github.com/dlang/phobos/pull/7322

--
December 17, 2019
https://issues.dlang.org/show_bug.cgi?id=7006

timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@gdcproject.org
           Severity|normal                      |regression

--- Comment #9 from timon.gehr@gmx.ch ---
The expression (-1)^^x for negative x used to work correctly (by accident) due to constant folding. This constant folding for pow is going away: https://github.com/dlang/dmd/commit/0f2889c3aa9fba5534e754dade0cae574b636d55

Therefore, if this issue is not fixed, we will have a regression in the next compiler release.

--
January 03, 2020
https://issues.dlang.org/show_bug.cgi?id=7006

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/phobos pull request #7322 "Fix Issue 7006 - std.math.pow (integral, integral) crashes on negative exponents" was merged into master:

- 357a4df94d62aeb45aa6feabac41adf2133502be by Bernhard Seckinger:
  Fix Issue 7006 - std.math.pow (integral, integral) crashes on negative
exponents

https://github.com/dlang/phobos/pull/7322

--