Skip to content

Duration.msg and Time.msg nanoseconds description #175

@jimmy-mcelwain

Description

@jimmy-mcelwain

In both the duration message and time message definitions the seconds description is (roughly) as follows:

Seconds component, range is valid over any possible int32 value.

And the nanoseconds description is:

Nanoseconds component in the range of [0, 1e9).

So, the seconds description seems pretty explicit that it can be negative. My assumption is that this generally means that:

  1. A time message can represent a time before the epoch
  2. A duration message can represent a negative duration

Those make sense to me.

But the nanoseconds description is weird to me. It says it is the "nanoseconds component". That makes sense for time and duration values with positive seconds values, but for a time or duration with a negative seconds, how does that work?

Specifically, how would a number between 0 and -1 be represented? Given that nanoseconds is of type uint32, it cannot be negative. But seconds is of type int32, and in C cannot represent negative zero.

For example, take -0.1 seconds. How would it be represented?

seconds: 0, nanoseconds: -100000000 -- doesn't work because nanoseconds must be positive
seconds: -0, nanoseconds: 100000000 -- doesn't work because negative zero isn't valid in C/isn't in the domain of int32.
seconds: -1, nanoseconds: 900000000 -- this would work, but goes against the description Nanoseconds component in the range of [0, 1e9).. It's also not very intuitive, but that's alright I guess if it works.

What is the expected way to represent this in C?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions