[Issue 7006] std.math.pow (integral, integral) crashes on negative exponents

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 27 23:37:14 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=7006


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug at yahoo.com.au


--- Comment #1 from Don <clugdbug at yahoo.com.au> 2011-11-27 23:36:13 PST ---
(In reply to comment #0)
> It seems to be by design:
> > if (n<0) return x/0; // Only support positive powers
> 
> But that does not make any sense. The results are well-defined if x!=0.

No, they aren't well defined. The result doesn't fit into an integer, unless x
is 1 or -1.   x^^n is always a bug if x is an integer other than +-1, and n is
a negative integer.

The idea behind the division by zero error is that some processors (such as
x86) also give a div by zero error on -1 / (-1 - int.max), because the result
isn't representable as an integer. It's ugly though.

Now that we have proper range checking, we should be able to statically
disallow it, and make n unsigned.

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


More information about the Digitalmars-d-bugs mailing list