-
-
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
Support BigDecimal comparison with and initialization from BigRational #5675
Support BigDecimal comparison with and initialization from BigRational #5675
Conversation
src/big/big_decimal.cr
Outdated
@@ -133,6 +134,11 @@ struct BigDecimal < Number | |||
initialize(num.to_s) | |||
end | |||
|
|||
# Creates a new `BigDecimal` from `BigRational`. | |||
def initialize(num : BigRational) | |||
initialize(num.to_f64) |
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.
How about num.numerator.to_big_d / num.denominator.to_big_d
?
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.
done & force-pushed
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.
Oops
5477b41
to
ac84c3b
Compare
src/big/big_decimal.cr
Outdated
@@ -133,6 +134,13 @@ struct BigDecimal < Number | |||
initialize(num.to_s) | |||
end | |||
|
|||
# Creates a new `BigDecimal` from `BigRational`. | |||
def initialize(num : BigRational) |
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.
but why not make this a self.new
then you can just return the original number instead of copying the value and scale...
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.
True indeed, I've forgot about that, thx! force-pushed again
ac84c3b
to
7503522
Compare
Is it GTG? Could we have a 2nd review here? |
This PR allows below code to work: