Skip to content

Loading…

Fixed Kernel#Float in 1.9 #1315

Merged
merged 1 commit into from

2 participants

@schmurfy

Fixed two failing specs for Kernel#Float, I am sure there is a better way but it works :p

@rue
Rubinius member

Looks OK, but can't be automatically merged. Can you rebase off HEAD?

@schmurfy

rebased, test all green.

@rue rue merged commit 23e6303 into rubinius:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 23, 2011
  1. @schmurfy

    Fixed Kernel#Float in 1.9

    schmurfy committed
This page is out of date. Refresh to see the latest.
Showing with 48 additions and 27 deletions.
  1. +0 −25 kernel/common/kernel.rb
  2. +26 −0 kernel/common/kernel18.rb
  3. +22 −0 kernel/common/kernel19.rb
  4. +0 −2 spec/tags/19/ruby/core/kernel/Float_tags.txt
View
25 kernel/common/kernel.rb
@@ -9,31 +9,6 @@ def __method__
return name
end
- def Float(obj)
- raise TypeError, "can't convert nil into Float" if obj.nil?
-
- case obj
- when Float
- obj
- when String
- valid_re = /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/
-
- m = valid_re.match(obj)
-
- if !m or !m.pre_match.empty? or !m.post_match.empty?
- raise ArgumentError, "invalid value for Float(): #{obj.inspect}"
- end
- obj.convert_float
- else
- coerced_value = Rubinius::Type.coerce_to(obj, Float, :to_f)
- if coerced_value.nan?
- raise ArgumentError, "invalid value for Float(): #{coerced_value.inspect}"
- end
- coerced_value
- end
- end
- module_function :Float
-
##
# MRI uses a macro named StringValue which has essentially the same
# semantics as obj.coerce_to(String, :to_str), but rather than using that
View
26 kernel/common/kernel18.rb
@@ -83,4 +83,30 @@ def Array(obj)
end
end
module_function :Array
+
+ def Float(obj)
+ raise TypeError, "can't convert nil into Float" if obj.nil?
+
+ case obj
+ when Float
+ obj
+ when String
+ valid_re = /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/
+
+ m = valid_re.match(obj)
+
+ if !m or !m.pre_match.empty? or !m.post_match.empty?
+ raise ArgumentError, "invalid value for Float(): #{obj.inspect}"
+ end
+ obj.convert_float
+ else
+ coerced_value = Rubinius::Type.coerce_to(obj, Float, :to_f)
+ if coerced_value.nan?
+ raise ArgumentError, "invalid value for Float(): #{coerced_value.inspect}"
+ end
+ coerced_value
+ end
+ end
+ module_function :Float
+
end
View
22 kernel/common/kernel19.rb
@@ -141,4 +141,26 @@ def Array(obj)
def =~(other)
nil
end
+
+ def Float(obj)
+ raise TypeError, "can't convert nil into Float" if obj.nil?
+
+ case obj
+ when Float
+ obj
+ when String
+ valid_re = /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/
+
+ m = valid_re.match(obj)
+
+ if !m or !m.pre_match.empty? or !m.post_match.empty?
+ raise ArgumentError, "invalid value for Float(): #{obj.inspect}"
+ end
+ obj.convert_float
+ else
+ Rubinius::Type.coerce_to(obj, Float, :to_f)
+ end
+ end
+ module_function :Float
+
end
View
2 spec/tags/19/ruby/core/kernel/Float_tags.txt
@@ -1,2 +0,0 @@
-fails:Kernel.Float returns the identical NaN if to_f is called and it returns NaN
-fails:Kernel#Float returns the identical NaN if to_f is called and it returns NaN
Something went wrong with that request. Please try again.