[ruby-core:96966] [Ruby master Bug#16518] Should we rationalize Rational's numerator automatically?
From:
stan001212@...
Date:
2020-01-22 08:42:52 UTC
List:
ruby-core #96966
Issue #16518 has been updated by st0012 (Stan Lo). Thanks for the quick response! I also found that it returns `BigDecimal` if any of its arguments is a `BigDecimal`: ``` irb(main):005:0> Rational(BigDecimal(1), 1).class => BigDecimal irb(main):006:0> Rational(BigDecimal(1), BigDecimal(1)).class => BigDecimal irb(main):007:0> Rational(0, BigDecimal(1)).class => BigDecimal irb(main):008:0> ``` ---------------------------------------- Bug #16518: Should we rationalize Rational's numerator automatically? https://bugs.ruby-lang.org/issues/16518#change-83991 * Author: st0012 (Stan Lo) * Status: Open * Priority: Normal * Assignee: mrkn (Kenta Murata) * Target version: * ruby -v: 2.6.5 * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- In this [Rails issue](https://github.com/rails/rails/issues/38041) we found that using `BigDecimal` as a `Rational`'s numerator can have inconsistent behaviors when the denominator gets bigger. For example: ``` > 1 == BigDecimal(1) => true > Rational(1, 1) == Rational(BigDecimal(1), 1) => true > Rational(1, 6) == Rational(BigDecimal(1), 6) => true > Rational(1, 60) == Rational(BigDecimal(1), 60) => false ``` So my question is, is this behavior expected? If it's not expected, do we have a plan to fix it? If it is, does it make sense to manually rationalize the numerator before passing it into the `Rational` call, in order to get a consistent result? -- 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>