[ruby-core:102816] [Ruby master Bug#6120] Float and BigDecimal bug in remainder in corner cases
From:
merch-redmine@...
Date:
2021-03-10 22:41:43 UTC
List:
ruby-core #102816
Issue #6120 has been updated by jeremyevans0 (Jeremy Evans).
I've submitted a pull request to fix this issue for Integer/Float: https://github.com/ruby/ruby/pull/4257
I've submitted an issue to the bigdecimal repository to fix the issue in BigDecimal: https://github.com/ruby/bigdecimal/issues/187
----------------------------------------
Bug #6120: Float and BigDecimal bug in remainder in corner cases
https://bugs.ruby-lang.org/issues/6120#change-90870
* Author: marcandre (Marc-Andre Lafortune)
* Status: Assigned
* Priority: Normal
* Assignee: marcandre (Marc-Andre Lafortune)
* ruby -v: r34927
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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:
1) foo.remainder(bar) == foo.remainder(-bar)
2) 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?
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>