-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Factor powers of ten before dividing BigDecimals #7218
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Sija 👍
@@ -148,6 +148,7 @@ describe BigDecimal do | |||
BigDecimal.new(-1) / BigDecimal.new(0) | |||
end | |||
BigDecimal.new(1).should eq(BigDecimal.new(1) / BigDecimal.new(1)) | |||
BigDecimal.new(10).should eq(BigDecimal.new(100, 1) / BigDecimal.new(100000000, 8)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not for this PR, but all of these assertions are written backwards: what one expects to get should be at the right-hand side.
@@ -204,6 +204,7 @@ struct BigDecimal < Number | |||
# ``` | |||
def div(other : BigDecimal, max_div_iterations = DEFAULT_MAX_DIV_ITERATIONS) : BigDecimal | |||
check_division_by_zero other | |||
other.factor_powers_of_ten |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since calling factor_powers_of_ten
is changing internal object state, should we dup
the other before calling it?
Fixes #7122