summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Schleifer <js@heap.zone>2018-05-26 16:46:35 +0200
committerJonathan Schleifer <js@heap.zone>2018-05-26 16:46:35 +0200
commit38793dcd459f03104499a7bb25ed0b8f10cea786 (patch)
treec693bb90139bc805ad1d1d1c251027c6df711325
parent2d9dc8cbbb1825d69b65c5c4640c49ad42a1a031 (diff)
Use trunc() instead of floor() in several places
floor() does not have the desired effect here when the number is negative.
-rw-r--r--src/OFDate.m18
-rw-r--r--src/OFThread.m4
-rw-r--r--utils/ofhttp/ProgressBar.m2
3 files changed, 12 insertions, 12 deletions
diff --git a/src/OFDate.m b/src/OFDate.m
index 60ffb037..24850a17 100644
--- a/src/OFDate.m
+++ b/src/OFDate.m
@@ -51,7 +51,7 @@ static OFMutex *mutex;
time_t seconds = (time_t)_seconds; \
struct tm tm; \
\
- if (seconds != floor(_seconds)) \
+ if (seconds != trunc(_seconds)) \
@throw [OFOutOfRangeException exception]; \
\
if (gmtime_r(&seconds, &tm) == NULL) \
@@ -62,7 +62,7 @@ static OFMutex *mutex;
time_t seconds = (time_t)_seconds; \
struct tm tm; \
\
- if (seconds != floor(_seconds)) \
+ if (seconds != trunc(_seconds)) \
@throw [OFOutOfRangeException exception]; \
\
if (localtime_r(&seconds, &tm) == NULL) \
@@ -75,7 +75,7 @@ static OFMutex *mutex;
time_t seconds = (time_t)_seconds; \
struct tm *tm; \
\
- if (seconds != floor(_seconds)) \
+ if (seconds != trunc(_seconds)) \
@throw [OFOutOfRangeException exception]; \
\
[mutex lock]; \
@@ -92,7 +92,7 @@ static OFMutex *mutex;
time_t seconds = (time_t)_seconds; \
struct tm *tm; \
\
- if (seconds != floor(_seconds)) \
+ if (seconds != trunc(_seconds)) \
@throw [OFOutOfRangeException exception]; \
\
[mutex lock]; \
@@ -110,7 +110,7 @@ static OFMutex *mutex;
time_t seconds = (time_t)_seconds; \
struct tm *tm; \
\
- if (seconds != floor(_seconds)) \
+ if (seconds != trunc(_seconds)) \
@throw [OFOutOfRangeException exception]; \
\
if ((tm = gmtime(&seconds)) == NULL) \
@@ -121,7 +121,7 @@ static OFMutex *mutex;
time_t seconds = (time_t)_seconds; \
struct tm *tm; \
\
- if (seconds != floor(_seconds)) \
+ if (seconds != trunc(_seconds)) \
@throw [OFOutOfRangeException exception]; \
\
if ((tm = localtime(&seconds)) == NULL) \
@@ -501,7 +501,7 @@ tmAndTzToTime(struct tm *tm, int16_t *tz)
- (uint32_t)microsecond
{
- return (uint32_t)((_seconds - floor(_seconds)) * 1000000);
+ return (uint32_t)((_seconds - trunc(_seconds)) * 1000000);
}
- (uint8_t)second
@@ -591,7 +591,7 @@ tmAndTzToTime(struct tm *tm, int16_t *tz)
wchar_t *buffer;
#endif
- if (seconds != floor(_seconds))
+ if (seconds != trunc(_seconds))
@throw [OFOutOfRangeException exception];
#ifdef HAVE_GMTIME_R
@@ -651,7 +651,7 @@ tmAndTzToTime(struct tm *tm, int16_t *tz)
wchar_t *buffer;
#endif
- if (seconds != floor(_seconds))
+ if (seconds != trunc(_seconds))
@throw [OFOutOfRangeException exception];
#ifdef HAVE_LOCALTIME_R
diff --git a/src/OFThread.m b/src/OFThread.m
index ca0de7d6..b0f0b8b8 100644
--- a/src/OFThread.m
+++ b/src/OFThread.m
@@ -204,7 +204,7 @@ callMain(id object)
rqtp.tv_sec = (time_t)timeInterval;
rqtp.tv_nsec = lrint((timeInterval - rqtp.tv_sec) * 1000000000);
- if (rqtp.tv_sec != floor(timeInterval))
+ if (rqtp.tv_sec != trunc(timeInterval))
@throw [OFOutOfRangeException exception];
nanosleep(&rqtp, NULL);
@@ -233,7 +233,7 @@ callMain(id object)
sleep((unsigned int)timeInterval);
usleep((unsigned int)lrint(
- (timeInterval - floor(timeInterval)) * 1000000));
+ (timeInterval - trunc(timeInterval)) * 1000000));
#endif
}
diff --git a/utils/ofhttp/ProgressBar.m b/utils/ofhttp/ProgressBar.m
index ae0945d8..52b485f1 100644
--- a/utils/ofhttp/ProgressBar.m
+++ b/utils/ofhttp/ProgressBar.m
@@ -106,7 +106,7 @@
for (size_t i = 0; i < (size_t)bars; i++)
[of_stdout writeString: @"█"];
if (bars < barWidth) {
- float rem = bars - floorf(bars);
+ float rem = bars - truncf(bars);
if (rem >= 0.875)
[of_stdout writeString: @"▉"];