You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BigInt should be better supported. Almost every math function that works with Int inputs should work with BigInt inputs.
You are only asking for the special case a ^ b where b = -1. It's currently handled by:
function bigint_pow(x::BigInt, y::Integer)
if y<0; throw(DomainError(y, "`y` cannot be negative.")); end
[for b < -1 the only result could be returning BigFloat, i.e. having BigInt power type-unstable, not under consideration here.] It's plausible to do extend this function for b = -1 only to and keep it type-stable, and looking at the code I think it can be done without slowing the other cases down. [I'm just not sure it's very valuable, and since such an extreme edge case, I'm ok with this issue just closed. I was basically answering @nhz2, here to not derail the other conversation.]
[Myself, I would prefer a ^ b to return Float64 (for all numbers, but not all types), i.e. a breaking change for 2.0 and then returning BigFloat for BigInt would seem sensible for compatibility, but since there's no Unsigned BigInt, unlike for other Integers we would have a dilemma.]
The text was updated successfully, but these errors were encountered:
This seems to be #3024 all over again. a ^ b can't return a BigFloat for b = big(-1) if we want it to be typestable, unless allBigInt powers are BigFloats (which would be inconvenient for a lot of number theory, I think), or unless we treat "literals" like big(-1) specially — though I don't see much point to this since for the case of a -1 literal you might as well do a literal power a^-1 (which already produces a BigFloat for a::BigInt).
stevengj
changed the title
Better support for power of BigInt needed?
negative powers of BigInt without DomainError
Jul 11, 2023
stevengj
changed the title
negative powers of BigInt without DomainError
negative powers of BigInt without DomainErrors?
Jul 11, 2023
This doesn't seems worth it so I'm closing. I don't want BigFloat result in general, because we have that, and want some way of getting BigInt. I was only addressing the question from @nhz2, and to match non-BigInt, it only addresses -1 ^ -1 and 1 ^ -1 as extra cases. Feel free to add the code for that, but it's such edge cases that I do not care. The issue you point to is for arbitrary a for a ^ b where b is negative. I still want that to return Float64 for non-BigInt, but see now it would lead to an inconsistency with BigInt power.
@nhz2 from #50486 (comment)
You are only asking for the special case a ^ b where b = -1. It's currently handled by:
[for b < -1 the only result could be returning BigFloat, i.e. having BigInt power type-unstable, not under consideration here.] It's plausible to do extend this function for b = -1 only to and keep it type-stable, and looking at the code I think it can be done without slowing the other cases down. [I'm just not sure it's very valuable, and since such an extreme edge case, I'm ok with this issue just closed. I was basically answering @nhz2, here to not derail the other conversation.]
What needs to be done then is similar to:
[Myself, I would prefer a ^ b to return Float64 (for all numbers, but not all types), i.e. a breaking change for 2.0 and then returning BigFloat for BigInt would seem sensible for compatibility, but since there's no Unsigned BigInt, unlike for other
Integer
s we would have a dilemma.]The text was updated successfully, but these errors were encountered: