Project

General

Profile

Actions

Bug #12980

closed

Time - Time to return a Rational

Added by matsuda (Akira Matsuda) over 7 years ago. Updated over 7 years ago.

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

Description

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) over 7 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) over 7 years ago

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

Updated by akr (Akira Tanaka) over 7 years ago

  • Status changed from Open to Feedback

Updated by mame (Yusuke Endoh) over 7 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 = Time.now; ...; p Time.now - 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) over 7 years ago

  • Status changed from Feedback to Closed

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0