It depends entirely on what you're going to do with it.
The tv_nsec
members of a struct timespec
is of type long
. You can set it to any value you like in the range LONG_MIN
to LONG_MAX
. If you perform a calculation that exceeds LONG_MAX
, which is at least 231-1, then you're going to have problems (undefined behavior that will probably show up as the value wrapping around).
Whether setting it to a value less than 0, or greater than or equal to one billion, will cause a problem depends on what you do with it. If you just want to print it, or perform some calculations on it, any valid long
value should be ok -- but the stored values are probably more useful if you normalize them.
clock_gettime()
should always give you a tv_nsec
value in the range 0..999999999.
POSIX requires the clock_settime()
, clock_nanosleep()
, and nanosleep()
functions to fail, and set errno
to EINVAL
, if "The tp argument specified a nanosecond value less than zero or greater than or equal to 1000 million."
References:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_settime.html
http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html
http://pubs.opengroup.org/onlinepubs/9699919799/functions/nanosleep.html