-
Notifications
You must be signed in to change notification settings - Fork 323
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
BigDecimalBuilder
and arithmetic operations.
#9950
Conversation
_ -> x | ||
|
||
java_to_enso x = case x of | ||
_ : BigDecimal -> Decimal.Value x |
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.
java_to_enso
is a conversion function that wraps java.math.BigDecimal
into Enso's Decimal
by calling the Value
constructor. That's correct wrapping. What kind of problem is associated with it? Are you searching for alternatives?
You can call the factory in Java, if you want. If you create a method:
public static Object factory(Function<BigDecimal,Object> f) {
return f.apply(BigDecimal.valueOf(1));
}
and call it from Enso as
IO.println <| factory Decimal.Value
then you should get Decimal.Value 1
. Other than this, I am not sure what to do/change.
@@ -651,6 +651,8 @@ add_specs suite_builder = | |||
|
|||
Decimal.new "12" . div (Decimal.new "0") . should_fail_with Arithmetic_Error | |||
|
|||
((Decimal.new "1") / (Decimal.new "3")) . should_fail_with Arithmetic_Error |
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.
Why does it fail? I don't understand.
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.
This fails because Decimal
defaults to infinite precision unless you use an explicit Math_Context
value.
The solution to this might be to use a Math_Context
by default, but doing so might be unexpected, and lose some of the value of Decimal
, which is that it attempts to handle precision automatically. I think we'll have to use this in anger before we can make that decision, to decide what the proper defaults should be.
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.
I see. I don't think it's a problem for it to fail by default, I just asked because I did not understand.
What is the error message in that case? I think we should try to ensure the error message is clear and ideally proposes the fix (use Math_Context to limit precision). Do you think that would be possible?
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.
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.
Looks good overall, but let's see how much the benchmarks are affected.
The benchmark comparison below shows that for Before:
After:
|
I also followed @JaroslavTulach's suggestion to try doing the conversion in Java rather than Enso. This was consistently slower for Conversion in Enso:
Conversion in Java:
|
Pull Request Description
Implements
BigDecimalBuilder
and arithmetic operations.Important Notes
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.