require 'bigdecimal'
require 'bigdecimal/util'  

def safe_add(a, b, prec)
  a, b = a.to_d, b.to_d
  rm = BigDecimal::ROUND_MODE
  orig = BigDecimal.mode(rm)

  BigDecimal.mode(rm, BigDecimal::ROUND_FLOOR)
  low = a.add(b, prec)

  BigDecimal.mode(rm, BigDecimal::ROUND_CEILING)
  high = a.add(b, prec)

  BigDecimal.mode(rm, orig)
  low..high
end

[[, ],
 [, ],
 [, ],
 [, ],
].each { |a, b| puts  }