Bug #6120

Float and BigDecimal bug in remainder in corner cases

Added by marcandre (Marc-Andre Lafortune) almost 9 years ago. Updated about 3 years ago.

Target version:



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:
1) foo.remainder(bar) == foo.remainder(-bar)
2) foo.remainder(bar) == foo when bar.abs > foo.abs

require 'bigdecimal'
bd ="4.2")
bd.remainder("+Infinity")) # => NaN, should be bd
bd.remainder("-Infinity")) # => NaN, should be bd
# (same with all signs reverse)

Reasons: same as float.

bd ="4.2")
bd.modulo("0")) # => ZeroDivisionError, probably ok?
bd.remainder("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?

Updated by naruse (Yui NARUSE) almost 9 years ago

Ruby's math should portably follow SuS. [ruby-core:28206]
You can fix it for Float/Math if it is obviously wrong and the right implementation is clear.

BigDecimal is little another world and it is up to mrkn.


Updated by shyouhei (Shyouhei Urabe) almost 9 years ago

  • Status changed from Open to Assigned

Updated by mame (Yusuke Endoh) about 8 years ago

  • Target version changed from 2.0.0 to 2.6

Should it be assigned to mrkn?

Yusuke Endoh

Updated by marcandre (Marc-Andre Lafortune) about 8 years ago

Didn't get around fixing it for 2.0.0. Will fix and then assign to mrkn for BigDecimal.


Updated by naruse (Yui NARUSE) about 3 years ago

  • Target version deleted (2.6)

Also available in: Atom PDF