Project

General

Profile

Bug #16518

Should we rationalize Rational's numerator automatically?

Added by st0012 (Stan Lo) 3 months ago. Updated 3 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:96942]

Description

In this Rails issue 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?

Also available in: Atom PDF