From: eregontp@... Date: 2017-01-18T10:42:45+00:00 Subject: [ruby-core:79122] [Ruby trunk Bug#13134] Rational() inconsistency Issue #13134 has been updated by Benoit Daloze. Floating-point numbers in String are exact, Float literal are inexact by nature. So I would not expect any relation with to_r, even more so when float division is involved. A Floating-point denominator in String sounds fine to me. The equation that should hold is Rational("#{a}/#{b}") == Rational(a) / Rational(b) with a and b floating-point numbers as Strings. Note that Float#rationalize produces a nicer-looking Rational, but there is no guarantee to how much precision might be lost on floating-point operations (e.g. 1.1-1.0), so it is moot to expect a relation between those. ---------------------------------------- Bug #13134: Rational() inconsistency https://bugs.ruby-lang.org/issues/13134#change-62534 * Author: Nobuyoshi Nakada * Status: Assigned * Priority: Normal * Assignee: Kenta Murata * Target version: * ruby -v: * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- `Rational()` parses a float, an integer divided by an integer, and a float divided by an integer. ```ruby Rational("3.1") #=> (31/10) Rational("3/2") #=> (3/2) Rational("3.1/2") #=> (31/20) ``` But a float is not allowed as a denominator. ```ruby Rational("3.1/2.0") #=> ArgumentError ``` I'd expect the last also passes and results in `(31/20)`, or the third also raises an `ArgumentError` A patch to let all pass. https://github.com/ruby/ruby/compare/trunk...nobu:parse_rat -- https://bugs.ruby-lang.org/ Unsubscribe: