summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2019-09-01 18:53:45 +0200
committerJonathan Schleifer <js@heap.zone>2019-09-01 18:53:45 +0200
commit8d2db52f33a7ada2d77888394685592f68b5f200 (patch)
treef8ef9c321a240410b0e0b4000daa405e3a5e2506
parent3d48375ec2f7e044fae1bec5a3ed27b95792339b (diff)
Remove remaining uses of lrint()
It was used to convert a time interval into seconds and microseconds or seconds and nanoseconds and introduced inaccuracies.
-rw-r--r--src/OFKqueueKernelEventObserver.m3
-rw-r--r--src/OFSelectKernelEventObserver.m3
-rw-r--r--src/OFThread.m10
-rw-r--r--src/condition_pthread.m4
4 files changed, 6 insertions, 14 deletions
diff --git a/src/OFKqueueKernelEventObserver.m b/src/OFKqueueKernelEventObserver.m
index 3d002502..e79a5f2d 100644
--- a/src/OFKqueueKernelEventObserver.m
+++ b/src/OFKqueueKernelEventObserver.m
@@ -19,7 +19,6 @@
#include <assert.h>
#include <errno.h>
-#include <math.h>
#ifdef HAVE_FCNTL_H
# include <fcntl.h>
@@ -165,7 +164,7 @@
return;
timeout.tv_sec = (time_t)timeInterval;
- timeout.tv_nsec = lrint((timeInterval - timeout.tv_sec) * 1000000000);
+ timeout.tv_nsec = (timeInterval - timeout.tv_sec) * 1000000000;
events = kevent(_kernelQueue, NULL, 0, eventList, EVENTLIST_SIZE,
(timeInterval != -1 ? &timeout : NULL));
diff --git a/src/OFSelectKernelEventObserver.m b/src/OFSelectKernelEventObserver.m
index 6617e7bd..bdced42e 100644
--- a/src/OFSelectKernelEventObserver.m
+++ b/src/OFSelectKernelEventObserver.m
@@ -27,7 +27,6 @@
#endif
#include <errno.h>
-#include <math.h>
#include <string.h>
#include <sys/time.h>
@@ -180,7 +179,7 @@
#else
timeout.tv_sec = (long)timeInterval;
#endif
- timeout.tv_usec = (int)lrint((timeInterval - timeout.tv_sec) * 1000);
+ timeout.tv_usec = (int)((timeInterval - timeout.tv_sec) * 1000);
#ifdef OF_AMIGAOS
if ((cancelSignal = AllocSignal(-1)) == (ULONG)-1)
diff --git a/src/OFThread.m b/src/OFThread.m
index 997bc83c..a1e52bd1 100644
--- a/src/OFThread.m
+++ b/src/OFThread.m
@@ -86,10 +86,6 @@
# import "atomic.h"
#endif
-#ifdef OF_DJGPP
-# define lrint(x) rint(x)
-#endif
-
#if defined(OF_HAVE_THREADS)
# import "tlskey.h"
# if defined(OF_AMIGAOS) && defined(OF_HAVE_SOCKETS)
@@ -250,7 +246,7 @@ static OFDNSResolver *DNSResolver;
struct timespec rqtp;
rqtp.tv_sec = (time_t)timeInterval;
- rqtp.tv_nsec = lrint((timeInterval - rqtp.tv_sec) * 1000000000);
+ rqtp.tv_nsec = (timeInterval - rqtp.tv_sec) * 1000000000;
if (rqtp.tv_sec != trunc(timeInterval))
@throw [OFOutOfRangeException exception];
@@ -275,8 +271,8 @@ static OFDNSResolver *DNSResolver;
@throw [OFOutOfRangeException exception];
sleep((unsigned int)timeInterval);
- usleep((unsigned int)lrint(
- (timeInterval - trunc(timeInterval)) * 1000000));
+ usleep((unsigned int)
+ (timeInterval - (unsigned int)timeInterval) * 1000000);
#endif
}
diff --git a/src/condition_pthread.m b/src/condition_pthread.m
index 74ed9894..240d1c2c 100644
--- a/src/condition_pthread.m
+++ b/src/condition_pthread.m
@@ -15,8 +15,6 @@
* file.
*/
-#include <math.h>
-
bool
of_condition_new(of_condition_t *condition)
{
@@ -48,7 +46,7 @@ of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex,
struct timespec ts;
ts.tv_sec = (time_t)timeout;
- ts.tv_nsec = lrint((timeout - ts.tv_sec) * 1000000000);
+ ts.tv_nsec = (timeout - ts.tv_sec) * 1000000000;
return (pthread_cond_timedwait(condition, mutex, &ts) == 0);
}