issue 7006 - std.math.pow (integral, integral) crashes on negative exponents
Timon Gehr
timon.gehr at gmx.ch
Sun Dec 15 18:31:14 UTC 2019
On 15.12.19 19:22, berni44 wrote:
> A few hours ago I closed issue 7006 [1] as a WONTFIX. Now
> timon.gehr at gmx.ch opened it again, without any explanation.
You didn't provide an explanation for closing the issue, so I assumed it
was an accident. -1^^-1 leading to "division by zero" instead of the
correct answer of -1 makes no sense at all.
> As I don't
> wont to start an edit war, I prefere to get some other opinions from the
> community.
>
> It's about the integer overload of pow() in std.math and the issue askes
> for adding support for negative exponents. IMHO there are two
> possibilites and non of them makes sense to me:
>
> a) Result type integral: There is no usecase,
Nonsense, e.g., (-1)^^i.
> because in almost all
> cases the result is a fraction which cannot be expressed as an integral
> type. Even when looking at this as a division with reminder, the value
> would always almost be 0. Again not very useful.
>
> b) Result type floating: This would be a breaking change. If the user
> wishes this behaviour he could convert the base to a floating type first
> and then call pow. Additionally it occasionally would produce wrong
> results as I pointed out in my closing message.
> ...
This is not an option.
> What do you think about this?
>
> [1] https://issues.dlang.org/show_bug.cgi?id=7006
A negative exponent should behave like a negative exponent. I.e., a^^-1
= 1/a. There's no good reason to do anything else.
More information about the Digitalmars-d
mailing list