From ffa036411d4dd3499efa4fbbf98f69687a35b0b7 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Thu, 28 Sep 2023 11:56:54 +0200 Subject: [PATCH] Make sure Integer can be treated as Float (#7909) --- .../Standard/Base/0.0.0-dev/src/Data/Numbers.enso | 2 ++ test/Tests/src/Data/Numbers_Spec.enso | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Numbers.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Numbers.enso index b3c92a28dc..9bb939d1a0 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Numbers.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Numbers.enso @@ -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 diff --git a/test/Tests/src/Data/Numbers_Spec.enso b/test/Tests/src/Data/Numbers_Spec.enso index e8ab6d7bc0..3399425e63 100644 --- a/test/Tests/src/Data/Numbers_Spec.enso +++ b/test/Tests/src/Data/Numbers_Spec.enso @@ -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