[ruby-core:88633] [Ruby trunk Bug#15023][Rejected] Time precision (in microsecond) inaccurate after performing strftime

From: nobu@...
Date: 2018-08-24 15:58:42 UTC
List: ruby-core #88633
Issue #15023 has been updated by nobu (Nobuyoshi Nakada).

Status changed from Open to Rejected

IEEE 754 floating point numbers are inexact, and cannot represent that value exactly.

    printf("%.20f\n", 1486525793.995) #=> 1486525793.99499988555908203125

You can use the second argument to `Time.at` if you have accurate fraction seconds.

    puts Time.at(1486525793, 995_000).strftime("%s.%6N") #=> 1486525793.995000

----------------------------------------
Bug #15023: Time precision (in microsecond) inaccurate after performing strftime
https://bugs.ruby-lang.org/issues/15023#change-73692

* Author: calvinchso (Calvin So)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Please see the example below. I think we should expect the result to be "1486525793.995". Right?

OS version: MacOS High Sierra 10.13.6

Ruby version: 2.5.1

~~~ ruby
2.5.1 :005 > Time.at(1486525793.995).strftime("%s.%6N")
 => "1486525793.994999"
~~~




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next