From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Timer errors in last few days (bignump change?) Date: Wed, 5 Sep 2018 16:28:43 -0700 Organization: UCLA Computer Science Department Message-ID: <76ddfcc7-4852-b6de-b4bc-90bdd3e6a4a5@cs.ucla.edu> References: <2e6d44fa-3520-c74a-4625-d8c401cfb078@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------827EEF723F0647099F8D1092" X-Trace: blaine.gmane.org 1536190046 11246 195.159.176.226 (5 Sep 2018 23:27:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 5 Sep 2018 23:27:26 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cc: Emacs developers To: Kaushal Modi Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 06 01:27:21 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxhCi-0002kO-TR for ged-emacs-devel@m.gmane.org; Thu, 06 Sep 2018 01:27:21 +0200 Original-Received: from localhost ([::1]:58554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxhEp-0000kp-3v for ged-emacs-devel@m.gmane.org; Wed, 05 Sep 2018 19:29:31 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxhEA-0000kh-63 for emacs-devel@gnu.org; Wed, 05 Sep 2018 19:28:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxhE6-0006wX-5s for emacs-devel@gnu.org; Wed, 05 Sep 2018 19:28:50 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:54694) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fxhE5-0006ty-Lt for emacs-devel@gnu.org; Wed, 05 Sep 2018 19:28:45 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 740571605B1; Wed, 5 Sep 2018 16:28:44 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id aABO9kp1ayVL; Wed, 5 Sep 2018 16:28:43 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8D0D2161130; Wed, 5 Sep 2018 16:28:43 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id mtDs073S6R4r; Wed, 5 Sep 2018 16:28:43 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 653AB1605B1; Wed, 5 Sep 2018 16:28:43 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:229319 Archived-At: This is a multi-part message in MIME format. --------------827EEF723F0647099F8D1092 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Kaushal Modi wrote: > Sorry for your wasted time. It was my mistake.. I redefined current-time. No problem. In penance you might want to take a look at the attached, which fixes a rounding error in that area that I noticed while looking into your report. > hat value even though way in future is still valid, right? Depends on the platform. It's not valid on platforms with 32-bit signed time_t; it is valid on almost every other platform. It > just happens that (encode-time 0 0 0 21 12 2100) returns that 2 element > time list. Not if time_t is 32-bit signed. > Is the issue with: > - time list having 2 elements? > - year being 2100? > - Or the delta between that fake `current-time' and real current-time too > big? The issue is that encode-time returns a format that timer-next-integral-multiple-of-time does not grok. I'm not sure it's worth fixing this now, since we're about to change timestamp formats anyway and I'd rather not be twiddling much with the old one (it'll still be supported blah blah blah, I just don't want to be enhancing it). --------------827EEF723F0647099F8D1092 Content-Type: text/x-patch; name="0001-Fix-timer.el-minor-rounding-error.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-timer.el-minor-rounding-error.patch" >From 67475a59e95919e2dbe25ae950450578afdfd0dc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 5 Sep 2018 16:19:47 -0700 Subject: [PATCH] Fix timer.el minor rounding error * lisp/emacs-lisp/timer.el (timer-next-integral-multiple-of-time): Fix rounding error by using integers rather than floats. * test/lisp/emacs-lisp/timer-tests.el (timer-test-multiple-of-time): New test. --- lisp/emacs-lisp/timer.el | 10 +++++----- test/lisp/emacs-lisp/timer-tests.el | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lisp/emacs-lisp/timer.el b/lisp/emacs-lisp/timer.el index 795554fec5..74d37b0eae 100644 --- a/lisp/emacs-lisp/timer.el +++ b/lisp/emacs-lisp/timer.el @@ -102,14 +102,14 @@ timer-next-integral-multiple-of-time "Yield the next value after TIME that is an integral multiple of SECS. More precisely, the next value, after TIME, that is an integral multiple of SECS seconds since the epoch. SECS may be a fraction." - (let* ((trillion 1e12) + (let* ((trillion 1000000000000) (time-sec (+ (nth 1 time) - (* 65536.0 (nth 0 time)))) + (* 65536 (nth 0 time)))) (delta-sec (mod (- time-sec) secs)) - (next-sec (+ time-sec (ffloor delta-sec))) - (next-sec-psec (ffloor (* trillion (mod delta-sec 1)))) + (next-sec (+ time-sec (floor delta-sec))) + (next-sec-psec (floor (* trillion (mod delta-sec 1)))) (sub-time-psec (+ (or (nth 3 time) 0) - (* 1e6 (nth 2 time)))) + (* 1000000 (nth 2 time)))) (psec-diff (- sub-time-psec next-sec-psec))) (if (and (<= next-sec time-sec) (< 0 psec-diff)) (setq next-sec-psec (+ sub-time-psec diff --git a/test/lisp/emacs-lisp/timer-tests.el b/test/lisp/emacs-lisp/timer-tests.el index 65e5dc9bde..fa92c1b64a 100644 --- a/test/lisp/emacs-lisp/timer-tests.el +++ b/test/lisp/emacs-lisp/timer-tests.el @@ -39,4 +39,9 @@ (if (fboundp 'debug-timer-check) (should (debug-timer-check)) t)) +(ert-deftest timer-test-multiple-of-time () + (should (equal + (timer-next-integral-multiple-of-time '(0 0 0 1) (1+ (ash 1 53))) + (list (ash 1 (- 53 16)) 1 0 0)))) + ;;; timer-tests.el ends here -- 2.17.1 --------------827EEF723F0647099F8D1092--