bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

some problems with float-time in emacs 21.0.101


From: Paul Eggert
Subject: some problems with float-time in emacs 21.0.101
Date: Tue, 27 Mar 2001 18:25:03 -0800 (PST)

In Emacs 21.0.101, (float-time '(0 0 999999)) returns
0.09999989999999999.  There are two problems with this answer.

* It's off nearly by a factor of 10.  The correct answer is 0.999999.

* The result is rounded incorrectly (so it's not even off by exactly a
  factor of 10 :-).

While looking into these problems, I noticed another problem with
float-time: it can lose information that is present in its arguments.
That means that it should not be used whenever precise time stamps are
required (e.g. when comparing file time stamps accurately).  Possibly,
some of float-time's uses in Emacs are incorrect for this reason, but
I haven't checked this.  In the meantime, the patch proposed below
warns about this problem in the doc string.

2001-03-27  Paul Eggert <address@hidden>

        * editfns.c (Ffloat_time): Fix off-by-factor-of-10 bug in the
        microseconds calcuation.  Avoid double-rounding problem.
        In doc string, warn that the result is approximate.

--- emacs-21.0.101/src/editfns.c        Fri Mar  2 04:53:05 2001
+++ emacs-21.0.101-fix/src/editfns.c    Tue Mar 27 18:01:45 2001
@@ -1358,7 +1358,10 @@ If an argument is given, it specifies a 
 instead of the current time.  The argument should have the forms:\n\
  (HIGH . LOW) or (HIGH LOW USEC) or (HIGH LOW . USEC).\n\
 Thus, you can use times obtained from `current-time'\n\
-and from `file-attributes'.")
+and from `file-attributes'.\n\
+\n\
+WARNING: Since the result is floating point, it may not be exact.\n\
+Do not use this function if precise time stamps are required.")
   (specified_time)
      Lisp_Object specified_time;
 {
@@ -1368,7 +1371,7 @@ and from `file-attributes'.")
   if (! lisp_time_argument (specified_time, &sec, &usec))
     error ("Invalid time specification");
 
-  return make_float (sec + usec * 0.0000001);
+  return make_float ((sec * 1e6 + usec) / 1e6);
 }
 
 /* Write information into buffer S of size MAXSIZE, according to the



reply via email to

[Prev in Thread] Current Thread [Next in Thread]