On Wed, 8 Mar 2017 13:34:18 +0200 Pekka Paalanen <[email protected]> wrote:
> On Wed, 1 Mar 2017 11:34:02 +0000 > Daniel Stone <[email protected]> wrote: > > > Paralleling timespec_to_nsec, converts to milliseconds. > > > > Signed-off-by: Daniel Stone <[email protected]> > > Reviewed-by: Pekka Paalanen <[email protected]> > > --- > > libweston/compositor.c | 2 +- > > shared/timespec-util.h | 11 +++++++++++ > > tests/timespec-test.c | 9 +++++++++ > > 3 files changed, 21 insertions(+), 1 deletion(-) > > > > v2: No changes. > > > > diff --git a/shared/timespec-util.h b/shared/timespec-util.h > > index 13948b1..c8e3cd6 100644 > > --- a/shared/timespec-util.h > > +++ b/shared/timespec-util.h > > @@ -93,6 +93,17 @@ timespec_to_nsec(const struct timespec *a) > > return (int64_t)a->tv_sec * NSEC_PER_SEC + a->tv_nsec; > > } > > > > +/* Convert timespec to milliseconds > > + * > > + * \param a timespec > > + * \return milliseconds > > Hi, > > might want to note, that this rounds to integer milliseconds towards > zero. It's not round() nor floor(), it's trunc(). > > Shall I just add that note when merging? > > + */ > > +static inline int64_t > > +timespec_to_msec(const struct timespec *a) > > +{ > > + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; > > +} Wait, I'm wrong, aren't I? The seconds value is always taken as is, nsec value (never negative) is always truncated towards zero. timespec { -2, 100 } > -2.0 s but it gets rounded to -2000 ms, i.e. down. That's not trunc(), that's floor(). Right? Thanks, pq
pgpAUTy6pjEqv.pgp
Description: OpenPGP digital signature
_______________________________________________ wayland-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/wayland-devel
