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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

tompng
Copy link
Member

@tompng tompng commented May 19, 2025

Introduce BigDecimal#_decimal_shift(n) for internal use.
BigMath.exp and BigMath.log now uses it instead of x * BigDecimal("1e#{shift}")

- x = x * BigDecimal("1e#{-exponent}")
+ x = x._decimal_shift(-exponent)
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

@tompng tompng force-pushed the decimal_shift branch 2 times, most recently from a5f23ae to 0512474 Compare July 6, 2025 05:53
@tompng tompng marked this pull request as ready for review July 19, 2025 09:37
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