Project

General

Profile

Bug #9192 ยป compare_decimal_float.rb

vatsu (Gustavo Sales), 12/02/2013 09:01 AM

 
require 'bigdecimal'

def compare_decimal_float(string_number)
d = BigDecimal.new(string_number)
f = string_number.to_f

puts "Instance number #{string_number}"

operators = { :== => :==, :< => :>, :> => :<, :<= => :>=, :>= => :<= }
operators.each do |op,inverse|
if (d.send(op,f)) ^ (f.send(inverse,d))
puts "Inconsistence:"
puts "#{d} #{op} #{f}"
puts "#{f} #{inverse} #{d}"
puts "========="
end
end

puts "###########"
end

(5..8).each { |i| compare_decimal_float("706.0#{i}") }
    (1-1/1)