Skip to content

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