From e194c86243ce0ff91809bdc090d5f8789b947e28 Mon Sep 17 00:00:00 2001 From: SamW Date: Wed, 17 Jun 2026 09:46:54 -0700 Subject: [PATCH 1/6] first commit, remove old unit tests --- test/stdlib/Float_test.rb | 195 ++------------------------------------ 1 file changed, 6 insertions(+), 189 deletions(-) diff --git a/test/stdlib/Float_test.rb b/test/stdlib/Float_test.rb index 4981ac9e2f..4eaf2d4e68 100644 --- a/test/stdlib/Float_test.rb +++ b/test/stdlib/Float_test.rb @@ -1,196 +1,13 @@ -require_relative "test_helper" +require_relative 'test_helper' -class FloatTest < StdlibTest - target Float - - def test_calc - 10.0 % 3 - 10.0 % 3.1 - 10.0 % 3r - - 3.0 * 1 - 3.0 * 1.1 - 3.0 * Complex.rect(1,2) - 3.0 * 2r - - 3.1 ** 2 - 3.1 ** 1.2 - 3.1 ** Complex.rect(1,2) - 3.1 ** 2r - - 3.0 + 1 - 3.0 + 1.1 - 3.0 + 2r - 3.0 + Complex.rect(1,2) - - 3.0 - 1 - 3.0 - 1.1 - 3.0 - 2r - 3.0 - Complex.rect(1,2) - - 3.0 / 1 - 3.0 / 1.1 - 3.0 / 2r - 3.0 / Complex.rect(1,2) - end - - def test_compare - 1.0 <=> 1 - 1.0 < 1 - 1.0 <= 3r - 1.0 > 3.1 - end - - def test_eq - a = 1.0 - - a == 1 - a == Object.new - - a === 1 - a === Object.new - end - - def test_abs - a = 3.1 - - a.abs - a.abs2 - end - - def test_angle - a = 3.1 - - a.angle - a.arg - -a.phase - end - - def test_ceil - a = 31.2 - - a.ceil - a.ceil(3) - a.ceil(ToInt.new) - end - - def test_coerce - 1.2.coerce(3) - 2.5.coerce(1.1) - end - - def test_denominator - a = 13.3 - - a.denominator - end - - def test_div - a = 12.3 - - a.div(3) - a.div(3.1) - a.div(12r) - - a.divmod(3) - a.divmod(3.1) - a.divmod(1r/5) - end - - def test_fdiv - a = 3.2 - - a.fdiv(3) - a.fdiv(3.1) - a.fdiv(1r/3) - a.fdiv(Complex.rect(1,2)) - end - - def test_floor - a = 3.2 - - a.floor() - a.floor(-1) - a.floor(ToInt.new) # No to_int support - end - - def test_modulo - a = 3.2 - - a.modulo(2) - a.modulo(1.1) - a.modulo(a) - end - - def test_numerator - a = 3.2 - - a.numerator - end - - def test_polar - 3.1.polar - (-3.12).polar - end - - def test_quo - a = 1.11 - - a.quo(3) - a.quo(1.3) - a.quo(1r/3) - a.quo(Complex.rect(1,2)) - end - - def test_rationalize - a = 1.22232.next_float - - a.rationalize - a.rationalize(3.11) - end - - def test_reminder - a = 1.4 - - a.remainder(3) - a.remainder(3.1) - a.remainder(3r/5) - end - - def test_round - a = 1.3 - - a.round(half: :up) - a.round(2, half: :up) - a.round(ToInt.new(-2), half: :up) - end - - def test_step - a = 1.3 - - a.step { break } - a.step(1, 2) { } - a.step(by: 3, to: 100) { } - end - - def test_to_s - a = 1.3 - - a.to_s - end - - def test_truncate - a = 1.3 +class FloatSingletonTest < Test::Unit::TestCase + include TestHelper - a.truncate - a.truncate(1) - end + testing 'singleton(Float)' end -class FloatConstantTest < Test::Unit::TestCase +class FloatInstanceTest < Test::Unit::TestCase include TestHelper - def test_constant - assert_const_type "Float", "Float::INFINITY" - end + testing 'Float' end From c40dbb00ded1edc18aa82c2814525fe2fa6d4088 Mon Sep 17 00:00:00 2001 From: SamW Date: Wed, 17 Jun 2026 09:55:03 -0700 Subject: [PATCH 2/6] added constants in --- core/float.rbs | 230 +++++++++++++++++++------------------- test/stdlib/Float_test.rb | 66 +++++++++++ 2 files changed, 182 insertions(+), 114 deletions(-) diff --git a/core/float.rbs b/core/float.rbs index d5d00a50a6..f3fa7f9644 100644 --- a/core/float.rbs +++ b/core/float.rbs @@ -253,6 +253,122 @@ # * #truncate: Returns `self` truncated to a given precision. # class Float < Numeric + # + # The minimum number of significant decimal digits in a double-precision + # floating point. + # + # Usually defaults to 15. + # + DIG: Integer + + # + # The difference between 1 and the smallest double-precision floating point + # number greater than 1. + # + # Usually defaults to 2.2204460492503131e-16. + # + EPSILON: Float + + # + # An expression representing positive infinity. + # + INFINITY: Float + + %a{deprecated:Does not actually exist} + Infinity: Float + + # + # The number of base digits for the `double` data type. + # + # Usually defaults to 53. + # + MANT_DIG: Integer + + # + # The largest possible integer in a double-precision floating point number. + # + # Usually defaults to 1.7976931348623157e+308. + # + MAX: Float + + # + # The largest positive exponent in a double-precision floating point where 10 + # raised to this power minus 1. + # + # Usually defaults to 308. + # + MAX_10_EXP: Integer + + # + # The largest possible exponent value in a double-precision floating point. + # + # Usually defaults to 1024. + # + MAX_EXP: Integer + + # + # The smallest positive normalized number in a double-precision floating point. + # + # Usually defaults to 2.2250738585072014e-308. + # + # If the platform supports denormalized numbers, there are numbers between zero + # and Float::MIN. 0.0.next_float returns the smallest positive + # floating point number including denormalized numbers. + # + MIN: Float + + # + # The smallest negative exponent in a double-precision floating point where 10 + # raised to this power minus 1. + # + # Usually defaults to -307. + # + MIN_10_EXP: Integer + + # + # The smallest possible exponent value in a double-precision floating point. + # + # Usually defaults to -1021. + # + MIN_EXP: Integer + + # + # An expression representing a value which is "not a number". + # + NAN: Float + + # + # The base of the floating point, or number of unique digits used to represent + # the number. + # + # Usually defaults to 2 on most systems, which would represent a base-10 + # decimal. + # + RADIX: Integer + + # Deprecated, do not use. + # + # Represents the rounding mode for floating point addition at the start time. + # + # Usually defaults to 1, rounding to the nearest number. + # + # Other modes include: + # + # -1 + # : Indeterminable + # 0 + # : Rounding towards zero + # 1 + # : Rounding to the nearest number + # 2 + # : Rounding towards positive infinity + # 3 + # : Rounding towards negative infinity + # + # + %a{deprecated} + ROUNDS: Integer + # -# The minimum number of significant decimal digits in a double-precision -# floating point. -# -# Usually defaults to 15. -# -Float::DIG: Integer - -# -# The difference between 1 and the smallest double-precision floating point -# number greater than 1. -# -# Usually defaults to 2.2204460492503131e-16. -# -Float::EPSILON: Float - -# -# An expression representing positive infinity. -# -Float::INFINITY: Float - -Float::Infinity: Float - -# -# The number of base digits for the `double` data type. -# -# Usually defaults to 53. -# -Float::MANT_DIG: Integer - -# -# The largest possible integer in a double-precision floating point number. -# -# Usually defaults to 1.7976931348623157e+308. -# -Float::MAX: Float - -# -# The largest positive exponent in a double-precision floating point where 10 -# raised to this power minus 1. -# -# Usually defaults to 308. -# -Float::MAX_10_EXP: Integer - -# -# The largest possible exponent value in a double-precision floating point. -# -# Usually defaults to 1024. -# -Float::MAX_EXP: Integer - -# -# The smallest positive normalized number in a double-precision floating point. -# -# Usually defaults to 2.2250738585072014e-308. -# -# If the platform supports denormalized numbers, there are numbers between zero -# and Float::MIN. 0.0.next_float returns the smallest positive -# floating point number including denormalized numbers. -# -Float::MIN: Float - -# -# The smallest negative exponent in a double-precision floating point where 10 -# raised to this power minus 1. -# -# Usually defaults to -307. -# -Float::MIN_10_EXP: Integer - -# -# The smallest possible exponent value in a double-precision floating point. -# -# Usually defaults to -1021. -# -Float::MIN_EXP: Integer - -# -# An expression representing a value which is "not a number". -# -Float::NAN: Float - -# -# The base of the floating point, or number of unique digits used to represent -# the number. -# -# Usually defaults to 2 on most systems, which would represent a base-10 -# decimal. -# -Float::RADIX: Integer - -# Deprecated, do not use. -# -# Represents the rounding mode for floating point addition at the start time. -# -# Usually defaults to 1, rounding to the nearest number. -# -# Other modes include: -# -# -1 -# : Indeterminable -# 0 -# : Rounding towards zero -# 1 -# : Rounding to the nearest number -# 2 -# : Rounding towards positive infinity -# 3 -# : Rounding towards negative infinity -# -# -Float::ROUNDS: Integer diff --git a/test/stdlib/Float_test.rb b/test/stdlib/Float_test.rb index 4eaf2d4e68..52f862eaf9 100644 --- a/test/stdlib/Float_test.rb +++ b/test/stdlib/Float_test.rb @@ -4,6 +4,72 @@ class FloatSingletonTest < Test::Unit::TestCase include TestHelper testing 'singleton(Float)' + + def test_constant_DIG + assert_const_type 'Integer', + 'Float::DIG' + end + + def test_constant_EPSILON + assert_const_type 'Float', + 'Float::EPSILON' + end + + def test_constant_INFINITY + assert_const_type 'Float', + 'Float::INFINITY' + end + + def test_constant_MANT_DIG + assert_const_type 'Integer', + 'Float::MANT_DIG' + end + + def test_constant_MAX + assert_const_type 'Float', + 'Float::MAX' + end + + def test_constant_MAX_10_EXP + assert_const_type 'Integer', + 'Float::MAX_10_EXP' + end + + def test_constant_MAX_EXP + assert_const_type 'Integer', + 'Float::MAX_EXP' + end + + def test_constant_MIN + assert_const_type 'Float', + 'Float::MIN' + end + + def test_constant_MIN_10_EXP + assert_const_type 'Integer', + 'Float::MIN_10_EXP' + end + + def test_constant_MIN_EXP + assert_const_type 'Integer', + 'Float::MIN_EXP' + end + + def test_constant_NAN + assert_const_type 'Float', + 'Float::NAN' + end + + def test_constant_RADIX + assert_const_type 'Integer', + 'Float::RADIX' + end + + def test_constant_ROUNDS + notify "Skipping test: Float::ROUNDS does not exist" unless defined? Float::ROUNDS + assert_const_type 'Integer', + 'Float::ROUNDS' + end end class FloatInstanceTest < Test::Unit::TestCase From c1a53542311c2a7083956ab1ee6cb16ece4f756c Mon Sep 17 00:00:00 2001 From: SamW Date: Wed, 17 Jun 2026 09:57:48 -0700 Subject: [PATCH 3/6] added instance method shell --- test/stdlib/Float_test.rb | 190 +++++++++++++++++++++++++++++++++++++- 1 file changed, 189 insertions(+), 1 deletion(-) diff --git a/test/stdlib/Float_test.rb b/test/stdlib/Float_test.rb index 52f862eaf9..fde2bfeef0 100644 --- a/test/stdlib/Float_test.rb +++ b/test/stdlib/Float_test.rb @@ -66,7 +66,7 @@ def test_constant_RADIX end def test_constant_ROUNDS - notify "Skipping test: Float::ROUNDS does not exist" unless defined? Float::ROUNDS + return unless defined? Float::ROUNDS assert_const_type 'Integer', 'Float::ROUNDS' end @@ -76,4 +76,192 @@ class FloatInstanceTest < Test::Unit::TestCase include TestHelper testing 'Float' + + def test_op_mod + omit 'todo' + end + + def test_op_mul + omit 'todo' + end + + def test_op_pow + omit 'todo' + end + + def test_op_add + omit 'todo' + end + + def test_op_sub + omit 'todo' + end + + def test_op_uneg + omit 'todo' + end + + def test_op_div + omit 'todo' + end + + def test_op_lth + omit 'todo' + end + + def test_op_leq + omit 'todo' + end + + def test_op_cmp + omit 'todo' + end + + def test_op_eq + omit 'todo' + end + + def test_op_eqq + omit 'todo' + end + + def test_op_gth + omit 'todo' + end + + def test_op_geq + omit 'todo' + end + + def test_abs + omit 'todo' + end + + def test_angle + omit 'todo' + end + + def test_arg + omit 'todo' + end + + def test_ceil + omit 'todo' + end + + def test_coerce + omit 'todo' + end + + def test_denominator + omit 'todo' + end + + def test_divmod + omit 'todo' + end + + def test_eql? + omit 'todo' + end + + def test_fdiv + omit 'todo' + end + + def test_finite? + omit 'todo' + end + + def test_floor + omit 'todo' + end + + def test_hash + omit 'todo' + end + + def test_infinite? + omit 'todo' + end + + def test_inspect + omit 'todo' + end + + def test_magnitude + omit 'todo' + end + + def test_modulo + omit 'todo' + end + + def test_nan? + omit 'todo' + end + + def test_negative? + omit 'todo' + end + + def test_next_float + omit 'todo' + end + + def test_numerator + omit 'todo' + end + + def test_phase + omit 'todo' + end + + def test_positive? + omit 'todo' + end + + def test_prev_float + omit 'todo' + end + + def test_quo + omit 'todo' + end + + def test_rationalize + omit 'todo' + end + + def test_round + omit 'todo' + end + + def test_to_f + omit 'todo' + end + + def test_to_i + omit 'todo' + end + + def test_to_int + omit 'todo' + end + + def test_to_r + omit 'todo' + end + + def test_to_s + omit 'todo' + end + + def test_truncate + omit 'todo' + end + + def test_zero? + omit 'todo' + end end From 4e15c0e7dcfde3f728a4b594757f0045be622378 Mon Sep 17 00:00:00 2001 From: SamW Date: Wed, 17 Jun 2026 10:13:00 -0700 Subject: [PATCH 4/6] first stage of singleton methods --- core/float.rbs | 17 +++-- test/stdlib/Float_test.rb | 128 +++++++++++++++++++++++++++++--------- 2 files changed, 107 insertions(+), 38 deletions(-) diff --git a/core/float.rbs b/core/float.rbs index f3fa7f9644..db219b9402 100644 --- a/core/float.rbs +++ b/core/float.rbs @@ -576,7 +576,7 @@ class Float < Numeric # # Related: Float#eql? (requires `other` to be a Float). # - def ==: (untyped) -> bool + def ==: (untyped other) -> bool # # Returns `true` if `other` has the same value as `self`, `false` otherwise: @@ -591,7 +591,7 @@ class Float < Numeric # # Related: Float#eql? (requires `other` to be a Float). # - def ===: (untyped) -> bool + alias === == # # Returns the quotient from dividing `self` by `other`: @@ -795,8 +795,7 @@ class Float < Numeric # f.quo(Rational(2, 1)) # => 1.57 # f.quo(Complex(2, 0)) # => (1.57+0.0i) # - def fdiv: (Complex) -> Complex - | (Numeric) -> Float + alias fdiv quo # # Returns a string containing a representation of `self`; depending of the value @@ -964,7 +963,7 @@ class Float < Numeric # 10.0 % 4.0 # => 2.0 # 10.0 % Rational(4, 1) # => 2.0 # - def modulo: (Numeric) -> Float + alias modulo % # # Returns `self` (which is already a Float). # - def to_f: () -> Float + def to_f: () -> self # # Returns 0 if `self` is positive, Math::PI otherwise. # - def angle: ... + alias angle arg # # Returns 0 if `self` is positive, Math::PI otherwise. # - alias arg angle + def arg: () -> (0 | Float) # NB: Can also return `NaN` if self is NaN # # Returns 0 if `self` is positive, Math::PI otherwise. # - alias phase angle + alias phase arg def polar: () -> [ Float, Integer | Float ] @@ -1108,8 +1117,8 @@ class Float < Numeric # f.quo(Rational(2, 1)) # => 1.57 # f.quo(Complex(2, 0)) # => (1.57+0.0i) # - def quo: (Complex) -> Complex - | (Numeric) -> Float + def quo: (Integer | Float other) -> Float + | [S, R] (Numeric::_Coerce[self, RBS::Ops::_Divide[S, R], S] other) -> R #