Make sure Integer can be treated as Float (#7909)

This commit is contained in:
Jaroslav Tulach 2023-09-28 11:56:54 +02:00 committed by GitHub
parent 8d926166ea
commit ffa036411d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -1171,6 +1171,8 @@ type Number_Parse_Error
to_display_text self =
"Could not parse " + self.text.to_text + " as a double."
Float.from (that:Integer) = (1.0 * that):Float
## A wrapper type that ensures that a function may only take positive integers.
type Positive_Integer
## PRIVATE

View File

@ -18,6 +18,15 @@ Integer.is_even self = self % 2 == 0
Float.get_fun_factor self = "Wow, " + self.to_text + " is such a fun number!"
type Complex
Value re:Float im:Float
new re=0 im=0 = Complex.Value re im
+ self (that:Complex) = Complex.new self.re+that.re self.im+that.im
Complex.from (that:Number) = Complex.new that
spec =
eps = 0.000001
almost_max_long = 9223372036854775806
@ -536,6 +545,12 @@ spec =
3.truncate . should_equal 3
-3.truncate . should_equal -3
Test.group "Number Conversions" <|
Test.specify "Returns its argument" <|
v1 = (Complex.new 1 2) + (Complex.new 3)
v2 = (Complex.new 1 2) + 3
v1 . should_equal v2
Test.group "BigInts" <|
expected_value = 2002115494039257055317447151023464523838443110452722331466645440244415760562579268801894716412