GNU bug report logs - #26162
time-duration screws up negative durations

Previous Next

Package: guile;

Reported by: Zefram <zefram <at> fysh.org>

Date: Sat, 18 Mar 2017 22:18:01 UTC

Severity: normal

Done: Mark H Weaver <mhw <at> netris.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 26162 in the body.
You can then email your comments to 26162 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#26162; Package guile. (Sat, 18 Mar 2017 22:18:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Zefram <zefram <at> fysh.org>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Sat, 18 Mar 2017 22:18:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Zefram <zefram <at> fysh.org>
To: bug-guile <at> gnu.org
Subject: time-duration screws up negative durations
Date: Sat, 18 Mar 2017 22:17:42 +0000
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 sent to Mark H Weaver <mhw <at> netris.org>:
You have taken responsibility. (Sun, 21 Oct 2018 23:32:02 GMT) Full text and rfc822 format available.

Notification sent to Zefram <zefram <at> fysh.org>:
bug acknowledged by developer. (Sun, 21 Oct 2018 23:32:02 GMT) Full text and rfc822 format available.

Message #10 received at 26162-done <at> debbugs.gnu.org (full text, mbox):

From: Mark H Weaver <mhw <at> netris.org>
To: Zefram <zefram <at> fysh.org>
Cc: 26162-done <at> debbugs.gnu.org
Subject: Re: bug#26162: time-duration screws up negative durations
Date: Sun, 21 Oct 2018 19:31:32 -0400
Zefram <zefram <at> fysh.org> writes:

> 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.

This is fixed by commit 437e1aa03659b77a8eb4b5c6d2b104c03d038564 on the
stable-2.2 branch.  I'm closing this bug now, but feel free to reopen if
appropriate.

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

Most of the code in the SRFI-19 reference implementation assumes that
the nanoseconds and seconds fields will have matching signs (if both
non-zero), so I've taken care to use that convention exclusively.

     Thanks,
       Mark




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 19 Nov 2018 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 131 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.