Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2^big(64) is an Int #13057

Closed
my-little-repository opened this issue Sep 10, 2015 · 9 comments
Closed

2^big(64) is an Int #13057

my-little-repository opened this issue Sep 10, 2015 · 9 comments
Labels
bug Indicates an unexpected problem or unintended behavior regression Regression in behavior compared to a previous version
Milestone

Comments

@my-little-repository
Copy link

Hi, I just tried the julia0.4rc. I see an unexpected behavior in some test. 2^big(64) is an Int, and thus underflows. I am pretty sure that this was a BigInt six month ago. Not sure if it is a bug though.

  julia> 2^big(64)
  0
@JeffBezanson JeffBezanson added bug Indicates an unexpected problem or unintended behavior regression Regression in behavior compared to a previous version labels Sep 10, 2015
@JeffBezanson
Copy link
Member

Wow, yes, this worked in 0.3.

@nolta
Copy link
Member

nolta commented Sep 10, 2015

d9bcdeb

I'm sorry, i should have made a PR, but it seemed pretty unambiguous at the time.

@JeffBezanson
Copy link
Member

Of course, the funny part is, not even GMP itself supports raising a BigInt to a BigInt power, since if your exponent is that large you're kind of in trouble.

@ivarne
Copy link
Member

ivarne commented Sep 11, 2015

What should be done here? Just revert d9bcdeb, or are there other ways that might satisfy both @my-little-repository and @nolta?

@JeffBezanson
Copy link
Member

I suppose on grounds that x^3 is x*x*x, the "3" is not really involved in the computation in some sense. So I'm not sure what's best here.

@staticfloat
Copy link
Member

The problem with that line of reasoning is that in 2^1.5, the fact that 1.5 is a float definitely changes the output type; so we have precedent for "unusual" exponent types taking over the output type of the exponentiation. I get that at its heart, floating-point exponentiation is a different algorithm than integer exponentiation, but from a purely "operator-as-a-blackbox" standpoint, I wouldn't say one viewpoint is immediately correct over the other.

@my-little-repository
Copy link
Author

In my use case, the exponent is the argument of a function, ultimately provided by the user. In case of an integer overflow, the user can just provide a BigInt as an argument and the whole computation will switch to arbitrary precision.

Sometimes we provide a BigInt as an input not because the input is a huge number, but because the computation leads to a huge output. Think about the factorial function. Or to some myexp2 function defined as myexp2(n) = 2^n.

Anyway, I am just pointing out an unexpected change in the 0.4 release candidate, I certainly can start writing two versions for each function that uses exponentiation, one for int, the other for bigint.

By the way, exp2 is in base and we have

julia> exp2(big(64))

1.844674407370955161600000000000000000000000000000000000000000000000000000000000e+19

I think that it would be more natural to return a BigInt here instead of a BigFloat. Or explicitely warn in the documentation that this function is not meant for integer typed computations.

@JeffBezanson
Copy link
Member

Yes, on the whole I'd say we should switch back to the 0.3 behavior. People do expect bigints to "propagate".

@ivarne ivarne added this to the 0.4.0 milestone Sep 13, 2015
@ivarne ivarne added good first issue Indicates a good issue for first-time contributors to Julia and removed good first issue Indicates a good issue for first-time contributors to Julia labels Sep 13, 2015
@ivarne ivarne closed this as completed in 324a21c Sep 13, 2015
ivarne added a commit that referenced this issue Sep 13, 2015
Closes #13057

This reverts commit d9bcdeb.

(cherry picked from commit 324a21c)
@tkelman
Copy link
Contributor

tkelman commented Sep 16, 2015

backported in #13107

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

6 participants