unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Zefram <zefram@fysh.org>
To: 26162@debbugs.gnu.org
Subject: bug#26162: time-duration screws up negative durations
Date: Sat, 18 Mar 2017 22:17:42 +0000	[thread overview]
Message-ID: <20170318221742.GI6518@fysh.org> (raw)

Computing a difference between two SRFI-19 times, using time-difference,
produces sensible results if the result is positive, but often nonsense
if it's negative:

scheme@(guile-user)> (use-modules (srfi srfi-19))
scheme@(guile-user)> (time-difference (make-time time-tai 0 1) (make-time time-tai 1000 0))
$1 = #<time type: time-duration nanosecond: 999999000 second: 0>
scheme@(guile-user)> (time-difference (make-time time-tai 1000 0) (make-time time-tai 0 1))
$2 = #<time type: time-duration nanosecond: 1000001000 second: 0>

The above is computing the same interval both ways round.  The first time
is correct, but the second is obviously not the negative of the first.
The correct result for the second would be

    #<time type: time-duration nanosecond: 1000 second: -1>

or possibly, at a stretch,

    #<time type: time-duration nanosecond: -999999000 second: 0>

(SRFI-19 isn't clear about which way it's meant to be normalised.
Having the nanoseconds field always non-negative is less surprising and
easier to maintain through computation.)

-zefram





             reply	other threads:[~2017-03-18 22:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-18 22:17 Zefram [this message]
2018-10-21 23:31 ` bug#26162: time-duration screws up negative durations Mark H Weaver

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-all from there: mbox

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=20170318221742.GI6518@fysh.org \
    --to=zefram@fysh.org \
    --cc=26162@debbugs.gnu.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).