From: "Stephan Kämper" Date: 2004-10-13T22:24:33+09:00 Subject: Re: "nan".to_f ? Hi, Markus wrote: > > The problem with this (in addition to some of my other contrived > examples, e.g. the non-convergent infinite series) is that we may want > to convert values to text and back (e.g., making XML) and would like to > be able to get something resembling the original values back. > Admittedly, it would be possible for users who wanted this to do it > themselves, but the performance consequences could be considerable. > > -- Markus I think there's not even a problem (or an SEP). You could easily - Add NaN as a constant to class Float - Implement String#to_f slightly bot not entirely different so as to return NaN if the string begins with NaN Something like this: class Float NaN = 0.0 / 0.0 end class String alias old_to_f to_f def to_f ( self =~ /^nan/i ) ? Float::NaN : self.old_to_f end end strings = [ "NaN1234", "nan", "nand is locical", "Nantucket? 70�07'W 41�18'N", "234234.234NaN", "1.0e23" ] strings.each { | s | puts "#{'%26s' % s} -> #{ s.to_f }" } Apparently this processing doesn't make sense for all Strings... Happy rubying Stephan