Project

General

Profile

Actions

Bug #11716

closed

Truncation error in Time xmlschema with fraction_digits.

Added by niroyb (Nick R) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
[ruby-core:71589]

Description

It looks like xmlschema with the fraction_digits parameter truncates the fractional second part.
Sometimes it truncates too much.
ex : 1447961542.26 with 2 fraction digits gives 1447961542.25 instead of 1447961542.26
Could be due to floating point representation. But tests seem to indicate otherwise.

$ irb $ require 'time' => true $ Time.at(1447961542.26).xmlschema(2) => "2015-11-19T11:32:22.25-08:00" $ Time.at(1447961542.269).xmlschema(2) => "2015-11-19T11:32:22.26-08:00" $ Time.at(1447961542.259).xmlschema(2) => "2015-11-19T11:32:22.25-08:00" $ Time.at(1447961542.25).xmlschema(2) => "2015-11-19T11:32:22.25-08:00" $ 1447961542.26*100.floor => 144796154226.0

Updated by akr (Akira Tanaka) over 8 years ago

  • Status changed from Open to Rejected

It's because 1447961542.26 is actually 1447961542.2599999904632568359375.

% ruby -e 'p "%.1000g" % 1447961542.26'
"1447961542.2599999904632568359375"

If 1447961542.26 is exactly given as rational, xmlschema(2) generates ".26" as the fractional part.

% ruby -rtime -e 'p Time.at(1447961542.26).xmlschema(2)'
"2015-11-20T04:32:22.25+09:00"
% ruby -rtime -e 'p Time.at(1447961542.26r).xmlschema(2)'
"2015-11-20T04:32:22.26+09:00"
Actions

Also available in: Atom PDF

Like0
Like0