Enable and fix mixed-comparison Decimal tests (#10583)

* from_string to from_text

* dec

* int/dec tests

* tests for f/d conversion warnings

* test warnings on mixed comparisons

* return inline types

* review

* disable mixed comparison test

* chaqngelog

* wip

* wip

* wip

* enable tests

* fix tests

* impl

* Revert "impl"

This reverts commit baeea8989f.
This commit is contained in:
GregoryTravis 2024-07-19 11:55:46 -04:00 committed by GitHub
parent 59f438e00d
commit 2e0fa89928
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 6 deletions

View File

@ -1128,7 +1128,7 @@ Decimal.from (that : Float) =
is_exceptional = that.is_nan || that.is_infinite
if is_exceptional then Error.throw (Illegal_Argument.Error "Cannot convert "+that.to_text+" to a Decimal") else
handle_java_exception <| attach_loss_of_numeric_precision that <|
Decimal.Value <| Decimal_Utils.fromFloatExact that
Decimal.Value <| Decimal_Utils.fromFloat that
## PRIVATE
Float.from (that : Decimal) = that.to_float

View File

@ -313,7 +313,7 @@ add_specs suite_builder =
values.map pr->
v = pr.at 0
d = Decimal.new v . remove_warnings
expected = pr.at 1 . to_float
expected = pr.at 1
d . should_equal expected
expected . should_equal d
@ -384,7 +384,7 @@ add_specs suite_builder =
suite_builder.group "(Decimal_Spec) edge cases" group_builder->
group_builder.specify "can support values outside the double range" <|
d = Decimal.new Float.max_value
(d == Float.max_value) . should_be_false
(d == Float.max_value) . should_be_true
((d * d) == Float.max_value) . should_be_false
((-(d * d)) == -Float.max_value) . should_be_false
Ordering.hash (d * d) . should_equal 2146435072
@ -622,12 +622,12 @@ add_specs suite_builder =
group_builder.specify "should attach a Loss_Of_Numeric_Precision warning when converting decimal to float with .from" <|
Problems.expect_only_warning Loss_Of_Numeric_Precision (Float.from (Decimal.new "56.34"))
group_builder.specify "Decimal.to_float cannot compare correctly with the original Decimal" <|
group_builder.specify "Decimal.to_float should compare correctly with the original Decimal" <|
huge_a = Decimal.new "3.4E300"
huge_a_float = Float.from huge_a
(huge_a_float == huge_a) . should_be_false
(huge_a == huge_a_float) . should_be_false
(huge_a_float == huge_a) . should_be_true
(huge_a == huge_a_float) . should_be_true
group_builder.specify "Decimal.to_integer should compare correctly with the original Decimal" <|
huge_a = Decimal.new "3.4E320"