diff options
author | Paul Eggert <eggert@Penguin.CS.UCLA.EDU> | 2018-10-22 19:31:15 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-10-22 19:34:49 -0700 |
commit | a38128561757c82fbd088cba379b7a253558c7f1 (patch) | |
tree | 3583478b760707dca52441fef3a19dfc1e954baf /test | |
parent | 8602bd855904acc1966f1a94a008f91bb3f88c18 (diff) | |
download | emacs-a38128561757c82fbd088cba379b7a253558c7f1.tar.gz |
Improve rounding in recent timer fix
* lisp/emacs-lisp/timer.el (timer-next-integral-multiple-of-time):
Use more-precise arithmetic to handle some boundary cases better
when rounding errors occur (Bug#33071).
* test/lisp/emacs-lisp/timer-tests.el:
(timer-next-integral-multiple-of-time-3):
New test, to test one of the boundary cases.
(timer-next-integral-multiple-of-time-2):
Redo so as to not assume a particular way of rounding 0.01.
Diffstat (limited to 'test')
-rw-r--r-- | test/lisp/emacs-lisp/timer-tests.el | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/test/lisp/emacs-lisp/timer-tests.el b/test/lisp/emacs-lisp/timer-tests.el index 7a5b9263b0b..e463b9e98bd 100644 --- a/test/lisp/emacs-lisp/timer-tests.el +++ b/test/lisp/emacs-lisp/timer-tests.el @@ -47,9 +47,21 @@ (ert-deftest timer-next-integral-multiple-of-time-2 () "Test bug#33071." (let* ((tc (current-time)) - (tce (encode-time tc 100)) - (nt (timer-next-integral-multiple-of-time tc 0.01)) - (nte (encode-time nt 100))) - (should (= (car nte) (1+ (car tce)))))) + (delta-ticks 1000) + (hz 128000) + (tce (encode-time tc hz)) + (tc+delta (time-add tce (cons delta-ticks hz))) + (tc+deltae (encode-time tc+delta hz)) + (tc+delta-ticks (car tc+deltae)) + (tc-nexte (cons (- tc+delta-ticks (% tc+delta-ticks delta-ticks)) hz)) + (nt (timer-next-integral-multiple-of-time + tc (/ (float delta-ticks) hz))) + (nte (encode-time nt hz))) + (should (equal tc-nexte nte)))) + +(ert-deftest timer-next-integral-multiple-of-time-3 () + "Test bug#33071." + (let ((nt (timer-next-integral-multiple-of-time '(32770 . 65539) 0.5))) + (should (time-equal-p 1 nt)))) ;;; timer-tests.el ends here |