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

Error: undefined method 'unsafe_shr' for BigInt #8691

Closed
5 tasks done
q9f opened this issue Jan 16, 2020 · 1 comment · Fixed by #8763
Closed
5 tasks done

Error: undefined method 'unsafe_shr' for BigInt #8691

q9f opened this issue Jan 16, 2020 · 1 comment · Fixed by #8763

Comments

@q9f
Copy link

q9f commented Jan 16, 2020

Exponentiation of an Int32 with a BigInt fails. I believe this is a bug even though, admittedly, I ran into this by coincidence and you usually don't want to exponentiate an Int32 with a BigInt. But I also think this should be possible.

  • Make sure a similar issue doesn't exist yet: use the search box
  • Include reproducible code: we should be able to paste it into an editor, compile and run it and get the same error as you. Otherwise it's impossible for us to reproduce the bug.
    # debug.cr
    
    require "big/big_int"
    
    pp 256 ** BigInt.new(8)
  • Don't only use play.crystal-lang.org or carc.in: code might be lost and the issue will remain incomplete. Write code in the issue itself.
  • Reduce code, if possible, to the minimum size that reproduces the bug.
  • If all of the above is impossible due to a large project, create a branch that reproduces the bug and point us to it.
  • Include Crystal compiler version (crystal -v) and OS. If possible, try to see if the bug still reproduces on master.
~/.opt/rlp.cr master*
❯ crystal run debug.cr --verbose --error-trace
In debug.cr:3:8

 3 | pp 256 ** BigInt.new(8)
            ^-
Error: instantiating 'Int32#**(BigInt)'


In /usr/lib/crystal/int.cr:281:27

 281 | exponent = exponent.unsafe_shr(1)
                           ^---------
Error: undefined method 'unsafe_shr' for BigInt

BigInt trace:

  /usr/lib/crystal/int.cr:281

          exponent = exponent.unsafe_shr(1)


  /usr/lib/crystal/int.cr:272

      def **(exponent : Int) : self


~/.opt/rlp.cr master*
❯ crystal version
Crystal 0.32.1 (2019-12-18)

LLVM: 9.0.0
Default target: x86_64-pc-linux-gnu

~/.opt/rlp.cr master*
❯ uname -a
Linux vesta 5.4.11-arch1-1 #1 SMP PREEMPT Sun, 12 Jan 2020 12:15:27 +0000 x86_64 GNU/Linux

It does not happen with two BigInt types:

pp BigInt.new(256) ** BigInt.new(8)
# => 18446744073709551616
@asterite
Copy link
Member

I think unsafe_shr should be added as an alias of >> to BigInt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants