From unknown Fri Jun 13 09:56:58 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#37046 <37046@debbugs.gnu.org> To: bug#37046 <37046@debbugs.gnu.org> Subject: Status: mod-test-add-nanosecond/valid fails Reply-To: bug#37046 <37046@debbugs.gnu.org> Date: Fri, 13 Jun 2025 16:56:58 +0000 retitle 37046 mod-test-add-nanosecond/valid fails reassign 37046 emacs submitter 37046 Glenn Morris severity 37046 minor thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 16 01:41:07 2019 Received: (at submit) by debbugs.gnu.org; 16 Aug 2019 05:41:07 +0000 Received: from localhost ([127.0.0.1]:52929 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hyUz5-0004lt-2D for submit@debbugs.gnu.org; Fri, 16 Aug 2019 01:41:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hyUz2-0004lG-PL for submit@debbugs.gnu.org; Fri, 16 Aug 2019 01:41:05 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:33084) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hyUyx-0004K6-Kh for submit@debbugs.gnu.org; Fri, 16 Aug 2019 01:40:59 -0400 Received: from rgm by fencepost.gnu.org with local (Exim 4.82) (envelope-from ) id 1hyUyp-0003fp-EY; Fri, 16 Aug 2019 01:40:53 -0400 From: Glenn Morris To: submit@debbugs.gnu.org Subject: mod-test-add-nanosecond/valid fails X-Debbugs-CC: eggert@cs.ucla.edu X-Spook: cryptographic illuminati Ermes SRI Central Intelligence X-Ran: :zCU#'`Uc)od5TmlN[?S^kD;/QYNZYzEA"UzA(|9 User-Agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/) MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Package: emacs Severity: minor Version: 27.0.50 Somewhere between 3548fd8 and 96ef76e (inclusive), mod-test-add-nanosecond/valid began failing. Ref eg https://hydra.nixos.org/build/98764057 https://hydra.nixos.org/build/98750439 From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 16 19:54:28 2019 Received: (at 37046-done) by debbugs.gnu.org; 16 Aug 2019 23:54:28 +0000 Received: from localhost ([127.0.0.1]:55181 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hym3A-0002q4-Bd for submit@debbugs.gnu.org; Fri, 16 Aug 2019 19:54:28 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:41674) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hym36-0002pp-U6 for 37046-done@debbugs.gnu.org; Fri, 16 Aug 2019 19:54:26 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 189271626EB; Fri, 16 Aug 2019 16:54:19 -0700 (PDT) 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 CJ1j0moUDdp8; Fri, 16 Aug 2019 16:54:17 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B085F162782; Fri, 16 Aug 2019 16:54:17 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu 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 QEZ83DrYcTOU; Fri, 16 Aug 2019 16:54:17 -0700 (PDT) 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 886671626EB; Fri, 16 Aug 2019 16:54:17 -0700 (PDT) Subject: Re: bug#37046: mod-test-add-nanosecond/valid fails To: Glenn Morris References: From: Paul Eggert Organization: UCLA Computer Science Department Message-ID: <5266caa8-bd52-fe30-fdc8-90e779d716a1@cs.ucla.edu> Date: Fri, 16 Aug 2019 16:54:17 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------38CEBA41912E5EFB0410798E" Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 37046-done Cc: 37046-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) This is a multi-part message in MIME format. --------------38CEBA41912E5EFB0410798E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Glenn Morris wrote: > Package: emacs > Severity: minor > Version: 27.0.50 > > Somewhere between 3548fd8 and 96ef76e (inclusive), > mod-test-add-nanosecond/valid began failing. > > Ref eg > https://hydra.nixos.org/build/98764057 > https://hydra.nixos.org/build/98750439 Thanks for reporting that. It should be fixed by commit 2019-08-16T23:25:02Z!eggert@cs.ucla.edu (attached) so I'm boldly closing the bug report. On a related topic, perhaps tests shouldn't depend on time-of-day? That kind of phase-of-the-moon stuff can make maintenance difficult - though, as it happened, it wasn't a problem this time as I discovered and fixed the bug before reading your bug report. --------------38CEBA41912E5EFB0410798E Content-Type: text/x-patch; name="0001-Fix-time-add-rounding-bug.patch" Content-Disposition: attachment; filename="0001-Fix-time-add-rounding-bug.patch" Content-Transfer-Encoding: quoted-printable >From f9fd12a30b3d94eb48f7b309907d136d7b2682ac Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 16 Aug 2019 16:25:02 -0700 Subject: [PATCH] Fix time-add rounding bug MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit Without this fix, time arithmetic yielded results that were not mathematically accurate, even though the exact results were representable; for example, (time-add 0 1e-13) yielded a timestamp equal to 0 instead of to 1e-13. * lisp/timezone.el (timezone-time-from-absolute): Let time-add do its thing rather than using floating point internally, which has rounding errors. We now have bignums and so don=E2=80=99t need floating point to avoid overflow issues. * src/timefns.c (timeform_sub_ps_p): New function. (time_arith): If either argument is a float, represent the result exactly instead of discarding sub-ps info. * test/lisp/timezone-tests.el (timezone-tests-time-from-absolute): Don=E2=80=99t assume (HI LO US PS) timestamp format. * test/src/emacs-module-tests.el (mod-test-add-nanosecond/valid): Don=E2=80=99t assume that time-add discards sub-ns info. * test/src/timefns-tests.el (time-rounding-tests): Add regression test to detect time-add rounding bug. --- lisp/timezone.el | 4 ++-- src/timefns.c | 14 +++++++++++--- test/lisp/timezone-tests.el | 7 ++++--- test/src/emacs-module-tests.el | 7 +++++-- test/src/timefns-tests.el | 3 +++ 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lisp/timezone.el b/lisp/timezone.el index ff0b266245..ce881a8c95 100644 --- a/lisp/timezone.el +++ b/lisp/timezone.el @@ -284,14 +284,14 @@ timezone-zone-to-minute =20 (defun timezone-time-from-absolute (date seconds) "Compute the UTC time equivalent to DATE at time SECONDS after midnigh= t. -Return a list suitable as an argument to `current-time-zone', +Return a Lisp timestamp suitable as an argument to `current-time-zone', or nil if the date cannot be thus represented. DATE is the number of days elapsed since the (imaginary) Gregorian date Sunday, December 31, 1 BC." (let* ((current-time-origin 719163) ;; (timezone-absolute-from-gregorian 1 1 1970) (days (- date current-time-origin)) - (seconds-per-day (float 86400)) + (seconds-per-day 86400) (day-seconds (* days seconds-per-day))) (condition-case nil (time-add day-seconds seconds) (range-error)))) diff --git a/src/timefns.c b/src/timefns.c index e9d1a9bf64..a4c1c4cb28 100644 --- a/src/timefns.c +++ b/src/timefns.c @@ -661,10 +661,18 @@ enum timeform TIMEFORM_HI_LO_US, /* seconds plus microseconds (HI LO US) */ TIMEFORM_NIL, /* current time in nanoseconds */ TIMEFORM_HI_LO_US_PS, /* seconds plus micro and picoseconds (HI LO US= PS) */ + /* These two should be last; see timeform_sub_ps_p. */ TIMEFORM_FLOAT, /* time as a float */ TIMEFORM_TICKS_HZ /* fractional time: HI is ticks, LO is ticks per se= cond */ }; =20 +/* True if Lisp times of form FORM can express sub-picosecond timestamps= . */ +static bool +timeform_sub_ps_p (enum timeform form) +{ + return TIMEFORM_FLOAT <=3D form; +} + /* From the valid form FORM and the time components HIGH, LOW, USEC and PSEC, generate the corresponding time value. If LOW is floating point, the other components should be zero and FORM should @@ -1016,8 +1024,8 @@ lispint_arith (Lisp_Object a, Lisp_Object b, bool s= ubtract) =20 /* Given Lisp operands A and B, add their values, and return the result as a Lisp timestamp that is in (TICKS . HZ) form if either A - or B are in that form, (HI LO US PS) form otherwise. Subtract - instead of adding if SUBTRACT. */ + or B are in that form or are floats, (HI LO US PS) form otherwise. + Subtract instead of adding if SUBTRACT. */ static Lisp_Object time_arith (Lisp_Object a, Lisp_Object b, bool subtract) { @@ -1077,7 +1085,7 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subt= ract) otherwise the (HI LO US PS) form for backward compatibility. */ return (EQ (hz, make_fixnum (1)) ? ticks - : aform =3D=3D TIMEFORM_TICKS_HZ || bform =3D=3D TIMEFORM_TICKS_HZ + : timeform_sub_ps_p (aform) || timeform_sub_ps_p (bform) ? Fcons (ticks, hz) : ticks_hz_list4 (ticks, hz)); } diff --git a/test/lisp/timezone-tests.el b/test/lisp/timezone-tests.el index 4b5f5617ec..c374042fa5 100644 --- a/test/lisp/timezone-tests.el +++ b/test/lisp/timezone-tests.el @@ -135,9 +135,10 @@ (should (equal (timezone-zone-to-minute "*invalid*") 0))) =20 (ert-deftest timezone-tests-time-from-absolute () - (should (equal (timezone-time-from-absolute (* 2020 365) ; Jan 1 2020 - (* 12 60 60)) ; 12:00 - '(23911 48704 0 0)))) + (should (time-equal-p + (timezone-time-from-absolute (* 2020 365) ; Jan 1 2020 + (* 12 60 60)) ; 12:00 + '(23911 48704 0 0)))) =20 ;; TODO: Write tests for timezone-tests-time-zone-from-absolute, which i= s a ;; bit tricky since the results depend on `current-time-zone'. diff --git a/test/src/emacs-module-tests.el b/test/src/emacs-module-tests= .el index c44c386d30..c510784731 100644 --- a/test/src/emacs-module-tests.el +++ b/test/src/emacs-module-tests.el @@ -335,12 +335,15 @@ module--test-assertion ;; New (TICKS . HZ) format. '(123456789 . 1000000000))) (ert-info ((format "input: %s" input)) - (let ((result (mod-test-add-nanosecond input))) + (let ((result (mod-test-add-nanosecond input)) + (desired-result + (let ((hz 1000000000)) + (time-add (time-convert input hz) (cons 1 hz))))) (should (consp result)) (should (integerp (car result))) (should (integerp (cdr result))) (should (cl-plusp (cdr result))) - (should (time-equal-p result (time-add input '(0 0 0 1000)))))))= ) + (should (time-equal-p result desired-result)))))) =20 (ert-deftest mod-test-add-nanosecond/nil () (should (<=3D (float-time (mod-test-add-nanosecond nil)) diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el index 1b1032deaa..362e7655a9 100644 --- a/test/src/timefns-tests.el +++ b/test/src/timefns-tests.el @@ -145,6 +145,9 @@ timefns-tests--have-leap-seconds (< 0.99 (/ (- (float-time a)) (float-time b)) 1.01)))))))) =20 +(ert-deftest time-rounding-tests () + (should (time-equal-p 1e-13 (time-add 0 1e-13)))) + (ert-deftest encode-time-dst-numeric-zone () "Check for Bug#35502." (should (time-equal-p --=20 2.17.1 --------------38CEBA41912E5EFB0410798E-- From unknown Fri Jun 13 09:56:58 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 14 Sep 2019 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator