digitalmars.D.bugs - [Issue 1976] New: Integral pow does not except negative powers
- d-bugmail puremagic.com (58/58) Apr 06 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1976
- d-bugmail puremagic.com (6/6) Apr 06 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1976
- d-bugmail puremagic.com (4/4) Apr 06 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1976
- d-bugmail puremagic.com (4/4) Apr 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1976
- Janice Caron (3/4) Apr 08 2008 Overload it for both int and uint, and have the int version accept
- Max Samukha (2/7) Apr 08 2008 Yes, there is pow(real, int) in phobos that calls row(real, real) if the...
- d-bugmail puremagic.com (9/9) Apr 07 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1976
http://d.puremagic.com/issues/show_bug.cgi?id=1976 Summary: Integral pow does not except negative powers Product: D Version: 2.012 Platform: PC OS/Version: Windows Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: bugzilla digitalmars.com ReportedBy: samukha voliacable.com Here is a modified version of pow that accepts both positive and negative powers: ---- real pow(real x, int n) { real p = 1.0, v; if (n < 0) { switch (n) { case -1: return 1 / x; case -2: return 1 / (x * x); default: } n = -n; v = p / x; } else { switch (n) { case 0: return 1.0; case 1: return x; case 2: return x * x; default: } v = x; } while (1) { if (n & 1) p *= v; n >>= 1; if (!n) break; v *= v; } return p; } ---- --
Apr 06 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1976 Created an attachment (id=242) --> (http://d.puremagic.com/issues/attachment.cgi?id=242&action=view) A pow patch for phobos --
Apr 06 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1976 Corrected the summary --
Apr 06 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1976 How about pow called with an unsigned exponent larger than int.max? --
Apr 07 2008
On 07/04/2008, d-bugmail puremagic.com <d-bugmail puremagic.com> wrote:How about pow called with an unsigned exponent larger than int.max?Overload it for both int and uint, and have the int version accept negative values?
Apr 08 2008
Janice Caron Wrote:On 07/04/2008, d-bugmail puremagic.com <d-bugmail puremagic.com> wrote:Yes, there is pow(real, int) in phobos that calls row(real, real) if the exponent is negative. Somehow the overload resolution error I got when calling pow with (double, int) made me think there is no such an overload. Anyway, though the proposed implementation may be faster for negative exponents, it doesn't work for int.min and so needs more thought.How about pow called with an unsigned exponent larger than int.max?Overload it for both int and uint, and have the int version accept negative values?
Apr 08 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1976 samukha voliacable.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID Right. My bad. --
Apr 07 2008