I am reading from a file a list of floating point numbers, some of
which are high precision. When I read such a number, I get a float out
of range warning:
% ff = Kernel.Float("1.0e-309")
% puts ff
test.rb:3: warning: Float 1.0e-309 out of range
0.0
The number is converted to 0.0 which is fine, but I would like to get
rid of this warning within the code.
Could anyone tell me how? Sorry if this is trivial, I am new to ruby,
and I haven't found a solution on the net (-W0 is not what I am looking
for).
I am reading from a file a list of floating point numbers, some of
which are high precision. When I read such a number, I get a float
out of range warning:
% ff = Kernel.Float("1.0e-309")
% puts ff
test.rb:3: warning: Float 1.0e-309 out of range
0.0
The number is converted to 0.0 which is fine, but I would like to get
rid of this warning within the code.
Could anyone tell me how? Sorry if this is trivial, I am new to ruby,
and I haven't found a solution on the net (-W0 is not what I am
looking for).
IMHO Float() should raise an exception in these cases; your program will
never be aware of the conversion error and thus cannot take any action
against this. Although this might break some code I'd strongly advocate
to put an exception in there. Unfortunaltely this won't help you right
now...
> % ff = Kernel.Float("1.0e-309")
> % puts ff
>
> test.rb:3: warning: Float 1.0e-309 out of range
..snip..
IMHO Float() should raise an exception in these cases; your program will
never be aware of the conversion error and thus cannot take any action
against this. Although this might break some code I'd strongly advocate
to put an exception in there. Unfortunaltely this won't help you right
now...
I'd tend to agree. Float() is a strict conversion, which is why
Float('bob') raises an exception.
My first thought was "1.0e-309".to_f, but this just produces the same warning.
Float("bob") # raise ArgumentError
"bob".to_f # no warning, =0
Float('1e-309') # warning but conversion
"1e-309".to_f # same behavior as Float()
Why would "1.0e-309" (a string without a good numerical float representation)
work significantly differently than "bob"? Assuming this is the
desired behavior, it seems inconsistent to my ignorant brain -- can
someone clarify it for me?
Cameron
ยทยทยท
On 9/2/05, Robert Klemme <bob.news@gmx.net> wrote: