Method: Fit::ScientificDouble#<=>

Defined in:
lib/fit/scientific_double.rb

#<=>(obj) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fit/scientific_double.rb', line 48

def <=> obj
  other = obj.to_f
  diff = @value - other

  # workaround the much more precise way of Ruby doing floats than Java
  return 0 if @precision.zero? and diff.abs < 1.0e-5

  precision = @precision > obj.precision ? @precision : obj.precision      
  return -1 if diff < -precision
  return 1 if diff > precision
  return 0 if @value.nan? and other.nan?
  return 1 if @value.nan?
  return -1 if other.nan?
  0
end