Skip to content

Implement BigDecimal#_decimal_shift for internal use #324

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tompng
Copy link
Member

@tompng tompng commented May 19, 2025

It can be used in sqrt calculation

BigDecimal(Integer.sqrt(BigDecimal(2)._decimal_shift(2*prec)))._decimal_shift(-prec)
irb(main):002> x = BigDecimal('1'*10000)
irb(main):003> 10000.times{x*10}
# processing time: 0.064433s
=> 10000
irb(main):004> 10000.times{x._decimal_shift 1}
# processing time: 0.041025s
=> 10000
irb(main):005> 10000.times{x/10}
# processing time: 0.287047s
=> 10000
irb(main):006> 10000.times{x._decimal_shift -1}
# processing time: 0.022237s
=> 10000

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

Successfully merging this pull request may close these issues.

1 participant