-
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
Various Decimal usability tweaks #10517
Conversation
@@ -89,7 +89,7 @@ type Decimal | |||
Value (big_decimal : BigDecimal) | |||
|
|||
## ICON input_number | |||
Construct a `Decimal` from a string or integer. | |||
Construct a `Decimal` from a string, integer or float. |
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.
Construct a `Decimal` from a string, integer or float. | |
Construct a `Decimal` from a Text, Integer or Float. |
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.
@@ -114,11 +114,21 @@ type Decimal | |||
Create a `Decimal` from a string. |
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.
Create a `Decimal` from a string. | |
Create a `Decimal` from a Text. |
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.
|
||
c = dec 12.345 | ||
dec : Text | Integer | Float -> Math_Context | Nothing -> Decimal ! Arithmetic_Error | Number_Parse_Error | ||
dec (x : Text | Integer | Float) (mc : Math_Context | Nothing = Nothing) -> Decimal ! Arithmetic_Error | Number_Parse_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.
I wonder what we should do with Math_Context | Nothing
- won't play nicely with the widgets.
One to think about in the decimal refinement.
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.
Shall we just add 2 constructors to Math_Context
? e.g. Custom
and Default
?
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.
|
||
## PRIVATE | ||
internal_representation : [Integer] | ||
internal_representation self = [self.unscaled_value, self.precision, self.scale] | ||
internal_representation self -> [Integer] = [self.unscaled_value, self.precision, self.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.
I don't think this is still valid. Probably accepted by the compiler, but I have no idea what it will do.
I think we should use
internal_representation self -> [Integer] = [self.unscaled_value, self.precision, self.scale] | |
internal_representation self -> Vector Integer = [self.unscaled_value, self.precision, self.scale] |
instead, as that's what is used most of the time.
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 is what happens when you write in other languages on the weekend.
to_text_without_scientific_notation self -> Text = self.big_decimal.toPlainString | ||
|
||
## ICON input_number | ||
Construct a `Decimal` from a string, integer or float. |
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 assume as @jdunkerley suggested we probably also want to replace string with Text here.
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.
@@ -97,15 +105,15 @@ add_specs suite_builder = | |||
mc4 = Math_Context.new 4 | |||
mc5 = Math_Context.new 5 | |||
|
|||
Problems.not_expect_warning (Decimal.new "123.25") | |||
Problems.not_expect_warning Any (Decimal.new "123.25") |
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_expect_warning
is especially useful if we do not expect a warning of type X but we acknowledge there may be other kinds of warnings.
If you expect no warnings at all, I'd recommend Problems.assume_no_problems
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.
Problems.expect_only_warning Loss_Of_Numeric_Precision (d < d) | ||
Problems.expect_only_warning Loss_Of_Numeric_Precision (d > d) | ||
Problems.expect_only_warning Loss_Of_Numeric_Precision (d <= d) | ||
Problems.expect_only_warning Loss_Of_Numeric_Precision (d >= 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.
Why do we have these warnings here? I don't think I understand. I'm comparing a Decimal with Decimal - why would that give me a warning???
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.
Yes, this is quite wrong and I missed it because of other problems with the test and with comparison. I marked this pending and it will be completed in #10163.
Equality
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.