Project

General

Profile

Bug #9192 ยป compare_decimal_float.rb

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

 
1
require 'bigdecimal'
2

    
3
def compare_decimal_float(string_number)
4
  d = BigDecimal.new(string_number)
5
  f = string_number.to_f
6

    
7
  puts "Instance number #{string_number}"
8

    
9
  operators = { :== => :==, :< => :>, :> => :<, :<= => :>=, :>= => :<= }
10
  operators.each do |op,inverse|
11
    if (d.send(op,f)) ^ (f.send(inverse,d))
12
      puts "Inconsistence:"
13
      puts "#{d} #{op} #{f}"
14
      puts "#{f} #{inverse} #{d}" 
15
      puts "========="
16
    end
17
  end
18

    
19
  puts "###########"
20
end
21

    
22
(5..8).each { |i| compare_decimal_float("706.0#{i}") }