]> Savannah Git Hosting - gnulib.git/commitdiff
dtotimespec: simplify
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 5 Mar 2017 04:42:52 +0000 (20:42 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 5 Mar 2017 04:43:20 +0000 (20:43 -0800)
* lib/dtotimespec.c (dtotimespec): Simplify.

ChangeLog
lib/dtotimespec.c

index 355f5c8c0770a0dde064c8679ca4f41126283e32..861dd6a78f7c8947af6bc427661b92f113589c3e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-03-04  Paul Eggert  <eggert@cs.ucla.edu>
+
+       dtotimespec: simplify
+       * lib/dtotimespec.c (dtotimespec): Simplify.
+
 2017-03-04  Bruno Haible  <bruno@clisp.org>
 
        test-calloc-gnu: Reenable test also for GCC 7.
index 9d81b68d817834489bc21d0b2570eb181bb353b8..3ca5a9cfd359a239d8b129976c571376caa0600b 100644 (file)
 struct timespec
 dtotimespec (double sec)
 {
-  double min_representable = TYPE_MINIMUM (time_t);
-  double max_representable =
-    ((TYPE_MAXIMUM (time_t) * (double) TIMESPEC_RESOLUTION
-      + (TIMESPEC_RESOLUTION - 1))
-     / TIMESPEC_RESOLUTION);
-
-  if (! (min_representable < sec))
+  if (! (TYPE_MINIMUM (time_t) < sec))
     return make_timespec (TYPE_MINIMUM (time_t), 0);
-  else if (! (sec < max_representable))
+  else if (! (sec < 1.0 + TYPE_MAXIMUM (time_t)))
     return make_timespec (TYPE_MAXIMUM (time_t), TIMESPEC_RESOLUTION - 1);
   else
     {