Bug #12980

Time - Time to return a Rational

Added by matsuda (Akira Matsuda) 9 months ago. Updated 8 months 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?


#1 [ruby-core:78329] Updated by matsuda (Akira Matsuda) 9 months 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.

#2 [ruby-core:78334] Updated by duerst (Martin Dürst) 9 months ago

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

#4 [ruby-core:78345] Updated by akr (Akira Tanaka) 9 months ago

  • Status changed from Open to Feedback

#5 [ruby-core:78351] Updated by mame (Yusuke Endoh) 9 months 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.

#6 [ruby-core:78509] Updated by matsuda (Akira Matsuda) 8 months 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