Bug #12980


Time - Time to return a Rational

Added by matsuda (Akira Matsuda) about 5 years ago. Updated almost 5 years ago.

Target version:
ruby -v:
ruby 2.4.0dev (2016-11-25 trunk 56897) [x86_64-darwin15]


Currently subtracting a Time from a Time returns a Float, which I guess causes #12952

Is there any reason this doesn't return a Rational?

Updated by matsuda (Akira Matsuda) about 5 years ago

Well, my assumption seems wrong.

0.5r.round also becomes 0, so this isn't really related to #12952
Still I'm wondering why Time - Time isn't Rational though.

Updated by duerst (Martin Dürst) about 5 years ago

  • Subject changed from Time - Time to return a Retional to Time - Time to return a Rational

Updated by akr (Akira Tanaka) about 5 years ago

  • Status changed from Open to Feedback

Updated by mame (Yusuke Endoh) about 5 years ago

I think of one philosophical reason and one practical reason.

A philosophical reason: many Time objects are inherently inexact. Since a Rational is considered exact, returning a Rational might convey the wrong message that the Time objects are exact.

A practical reason: Time is often used for a simple benchmark tool. Consider "t =; ...; p - t" prints, such as (631882841/200000000) or (1590642983/500000000). It is difficult for human to read and compare the result.

Updated by matsuda (Akira Matsuda) almost 5 years ago

  • Status changed from Feedback to Closed

All right. Sounds rational. Thank you for the explanation, Mame-san and akr-san!


Also available in: Atom PDF