[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Incorrect time unit names
From: |
Gary E. Miller |
Subject: |
Re: Incorrect time unit names |
Date: |
Sat, 9 Oct 2021 14:02:03 -0700 |
Yo Mick!
Thanks! Your patch is pushed to git head.
On Sat, 9 Oct 2021 20:46:59 +0100
Mick Durkin <mickdurkinuk@gmail.com> wrote:
> Hi,
>
> While inspecting the code of the tests for timespecs and the
> corresponding include file, I noticed one of the conversions was
> "reversed".
>
> Specifically, there was a #define for the number of milliseconds in a
> nanosecond, which is clearly named backwards although the use in the
> code was correct.
>
> Below are the 2 diffs I generated to correct this. Not important, but
> it satisfies my OCD 8^).
>
> BR
>
> Mick
> ===========================================================
>
> Change to timespec.h
>
> $ git diff -u include/timespec.h
> diff --git a/include/timespec.h b/include/timespec.h
> index f608cb4b1..c0dc36cd2 100644
> --- a/include/timespec.h
> +++ b/include/timespec.h
> @@ -10,13 +10,13 @@
> #include <stdbool.h> /* for bool */
>
> #define NS_IN_SEC 1000000000LL /* nanoseconds in a second
> */ -#define MS_IN_NS 1000000LL /* milliseconds in a
> nano second */ +#define NS_IN_MS 1000000LL /*
> nanoseconds in a millisecond */ #define US_IN_SEC 1000000LL
> /* microseconds in a second */ #define MS_IN_SEC 1000LL
> /* milliseconds in a second */
>
> -/* convert a timespec_t to an int64_t of milli seconds */
> +/* convert a timespec_t to an int64_t of milliseconds */
> #define TSTOMS(ts) ((int64_t)((ts)->tv_sec) * MS_IN_SEC + \
> - (int64_t)((ts)->tv_nsec / MS_IN_NS))
> + (int64_t)((ts)->tv_nsec / NS_IN_MS))
>
> /* normalize a timespec
> *
>
> ===========================================================
>
> Change to test_timespec.c
>
> $ git diff -u tests/test_timespec.c
> diff --git a/tests/test_timespec.c b/tests/test_timespec.c
> index d2199fa0c..a45b99a29 100644
> --- a/tests/test_timespec.c
> +++ b/tests/test_timespec.c
> @@ -172,8 +172,8 @@ struct ts_to_ms_test ts_to_ms_tests[] = {
> { TS_N_ONEM, -60000, 0},
> { TS_N_ONEH, -3600000, 0},
> { TS_N_ONED, -86400000, 0},
> - { { -1, MS_IN_NS}, -999, 0},
> - { { -1, -MS_IN_NS}, -1001, 0},
> + { { -1, NS_IN_MS}, -999, 0},
> + { { -1, -NS_IN_MS}, -1001, 0},
> // Note no (extra) loss of precision on the following
> { TS_2037, 2145916799000ULL, 0},
> { TS_2037_ONE, 2145916799000ULL, 0},
>
RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
gem@rellim.com Tel:+1 541 382 8588
Veritas liberabit vos. -- Quid est veritas?
"If you can't measure it, you can't improve it." - Lord Kelvin
pgpq0GpON6YKf.pgp
Description: OpenPGP digital signature