[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Your `timer-relative-time' code
From: |
Ehud Karni |
Subject: |
Re: Your `timer-relative-time' code |
Date: |
Sun, 27 May 2001 11:06:28 +0300 |
On Fri, 25 May 2001 16:11:56 -0400 (EDT), squash@math.ufl.edu (Jonathan LF
King) wrote:
>
> You sent me a fix for `timer-relative-time' which works with a
> negative argument. My copy of your code has "(!= micro 0)". Did
> you intend the "!=" to be "\=" perhaps?
> If yes, then I recommend `(not (zerop micro))'.
Thank you. I did mean /=.
I don't see the big advantage of `(not (zerop' over `(/= 0'. May be
if there was `(nzero' function it was better.
I list the fixed defun below.
Ehud.
(defun timer-relative-time (time secs &optional usecs)
"Advance TIME by SECS seconds and optionally USECS microseconds.
SECS may be a fraction."
(let ((high (car time))
(low (if (consp (cdr time)) (nth 1 time) (cdr time)))
(micro (if (numberp (car-safe (cdr-safe (cdr time))))
(nth 2 time)
0))
quotient)
;; Add
(if usecs (setq micro (+ micro usecs)))
(if (floatp secs)
(setq micro (+ micro (floor (* 1000000 (- secs (floor secs)))))))
(setq low (+ low (floor secs)))
;; Normalize
(setq quotient (/ micro 1000000))
(setq micro (mod micro 1000000))
;; Fix for possible negative micro
(and (< quotient 0)
(/= micro 0)
(setq quotient (1- quotient)))
(setq low (+ low quotient))
(setq quotient (/ low 65536))
(setq low (logand low 65535))
;; Fix for possible negative low
(and (< quotient 0)
(/= low 0)
(setq quotient (1- quotient)))
(setq high (+ high quotient))
(list high low (and (/= micro 0) micro))))
--
Ehud Karni Mivtach - Simon Insurance /"\
Tel: +972-3-6212-757 Fax: +972-3-6292-544 \ / ASCII Ribbon Campaign
(USA) Fax and voice mail: 1-815-5509341 X Against HTML Mail
Better Safe Than Sorry / \
mailto:ehud@unix.simonwiesel.co.il http://www.simonwiesel.co.il
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Your `timer-relative-time' code,
Ehud Karni <=