ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: akr@fsij.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:71592] [Ruby trunk - Bug #11716] [Rejected] Truncation error in Time xmlschema with fraction_digits.
Date: Thu, 19 Nov 2015 22:55:20 +0000	[thread overview]
Message-ID: <redmine.journal-54975.20151119225517.e9076d21b6bdba16@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11716.20151119200201@ruby-lang.org

Issue #11716 has been updated by Akira Tanaka.

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"
```



----------------------------------------
Bug #11716: Truncation error in Time xmlschema with fraction_digits.
https://bugs.ruby-lang.org/issues/11716#change-54975

* Author: Nick R
* Status: Rejected
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
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
`



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

      parent reply	other threads:[~2015-11-19 22:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11716.20151119200201@ruby-lang.org>
2015-11-19 20:02 ` [ruby-core:71589] [Ruby trunk - Bug #11716] [Open] Truncation error in Time xmlschema with fraction_digits niroyb
2015-11-19 22:55 ` akr [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-54975.20151119225517.e9076d21b6bdba16@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).