Actions
Bug #6120
closedFloat and BigDecimal bug in remainder in corner cases
Description
Currently:
4.2.remainder(+Float::INFINITY) # => 4.2, ok
4.2.remainder(-Float::INFINITY) # => NaN, should be 4.2
# (same with all signs reversed)
Reasons the remainder should be 4.2 and not NaN:
- foo.remainder(bar) == foo.remainder(-bar)
- foo.remainder(bar) == foo when bar.abs > foo.abs
Similarly:
require 'bigdecimal'
bd = BigDecimal.new("4.2")
bd.remainder(BigDecimal.new("+Infinity")) # => NaN, should be bd
bd.remainder(BigDecimal.new("-Infinity")) # => NaN, should be bd
# (same with all signs reverse)
Reasons: same as float.
Finally:
bd = BigDecimal.new("4.2")
bd.modulo(BigDecimal.new("0")) # => ZeroDivisionError, probably ok?
bd.remainder(BigDecimal.new("0")) # => NaN, should be probably raise a ZeroDivisionError?
Like in #6044, this could be decided either way, as long as there is consistency. Anyone prefer NaN to raising a ZeroDivisionError?
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0