From: Caleb Clausen Date: 2010-08-12T00:18:08+09:00 Subject: Re: "NaN".to_f revisited On 8/11/10, Brian Candler wrote: > Might give some strange behaviour though: > > "1$".to_f => 1.0 > "nonsense".to_f => 0.0 > "nanotubes".to_f => Nan ? > "inferiority".to_f => Inf ? Normally if the string starts with non-numeric characters, converting to numbers yields a zero result. This is to remain consistent with atof and strtod from the standard c library. On my machine, the man page for strtod contains this paragraph: Alternatively, if the portion of the string following the optional plus or minus sign begins with ``INFINITY'' or ``NAN'', ignoring case, it is interpreted as an infinity or a quiet NaN, respectively. In practice, strtod seems to actually recognize INF rather than the fully-spelled-out INFINITY as the trigger for returning infinity. So, your last 2 examples would return NaN and Inf if passed to strtod.