unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#26162: time-duration screws up negative durations
@ 2017-03-18 22:17 Zefram
  2018-10-21 23:31 ` Mark H Weaver
  0 siblings, 1 reply; 2+ messages in thread
From: Zefram @ 2017-03-18 22:17 UTC (permalink / raw)
  To: 26162

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#26162: time-duration screws up negative durations
  2017-03-18 22:17 bug#26162: time-duration screws up negative durations Zefram
@ 2018-10-21 23:31 ` Mark H Weaver
  0 siblings, 0 replies; 2+ messages in thread
From: Mark H Weaver @ 2018-10-21 23:31 UTC (permalink / raw)
  To: Zefram; +Cc: 26162-done

Zefram <zefram@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





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-10-21 23:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-18 22:17 bug#26162: time-duration screws up negative durations Zefram
2018-10-21 23:31 ` Mark H Weaver

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