U
Une Bévue
i need to test float numbers within an epsilon, then i've extended the
Float clas like that :
class Float
def ===( aFloat, eps = 1.0e-10)
begin
clazz = aFloat.class.to_s
raise "Argument \"#{aFloat}\" must be a Float (being of
#{clazz})." if clazz != "Float"
( self > aFloat - eps ) && ( self < aFloat + eps )
rescue
puts "An error occurred: #{$!}"
nil
end
end
end
this works as expected except when i want not to use the default value
for eps where i couldn't find the correct syntax :
a = 1.000000001
b = 1.00000000012
p ( a ===( b, 0.001) ).to_s
gave me :
[...] syntax error, unexpected ')', expecting tCOLON2 or '[' or '.'
p ( a ===( b, 0.001) ).to_s
^
why ???
Float clas like that :
class Float
def ===( aFloat, eps = 1.0e-10)
begin
clazz = aFloat.class.to_s
raise "Argument \"#{aFloat}\" must be a Float (being of
#{clazz})." if clazz != "Float"
( self > aFloat - eps ) && ( self < aFloat + eps )
rescue
puts "An error occurred: #{$!}"
nil
end
end
end
this works as expected except when i want not to use the default value
for eps where i couldn't find the correct syntax :
a = 1.000000001
b = 1.00000000012
p ( a ===( b, 0.001) ).to_s
gave me :
[...] syntax error, unexpected ')', expecting tCOLON2 or '[' or '.'
p ( a ===( b, 0.001) ).to_s
^
why ???