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

berni44 dlang at d-ecke.de
Sun Dec 15 19:52:14 UTC 2019


On Sunday, 15 December 2019 at 18:31:14 UTC, Timon Gehr wrote:
> You didn't provide an explanation for closing the issue, so I 
> assumed it was an accident.

I wrote something about the floating result stuff, which was 
meant as an explanation. Sorry, if that wasn't clear.

> -1^^-1 leading to "division by zero" instead of the correct 
> answer of -1 makes no sense at all.

I agree, that "division by zero" is not the best here. I guess, 
that the original programmer wanted to avoid throwing an 
exception.

>> a) Result type integral: There is no usecase,
>
> Nonsense, e.g., (-1)^^i.

Yeah, but what do you want to do with that? If the base is 
something other than -1, 0 or 1 the result is a fraction, which 
cannot be represented by an integral type. What should be the 
outcome of the function in that case?

>> 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.

OK. Here we have the same oppinion. :-)

> A negative exponent should behave like a negative exponent. 
> I.e., a^^-1 = 1/a. There's no good reason to do anything else.

Meanwhile I think, I understand, what you want to have. That 
would mean, that the answer of my question above would be 0 for 
all fractions. Correct? I'm just not sure, if this is the best 
alternative...

I'll file a PR with that and we'll see, what the reviewers will 
say.



More information about the Digitalmars-d mailing list