Permalink
Browse files

Merge pull request #1315 from schmurfy/kernel_float

Fixed Kernel#Float in 1.9
  • Loading branch information...
rue committed Oct 23, 2011
2 parents df45c82 + a36988c commit 23e6303b16a0cbbb90250a18ed3a5d29e36341b1
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
@@ -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
@@ -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
@@ -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
@@ -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

0 comments on commit 23e6303

Please sign in to comment.