A robot event log may store timestamps as integer nanoseconds. If an analysis job converts each absolute timestamp to floating point before subtracting, nearby events can collapse onto the same number. The subsequent subtraction can report zero duration even though the original log has distinct timestamps. When the source provides exact integer ticks, subtract the reference tick first and then convert the result to the units the analysis needs.
This example uses invented timestamps near a large epoch count and was checked with NumPy 2.5.2. The values are synthetic. The example demonstrates numerical representation and says nothing about the accuracy of a physical clock or a timestamping device.
Check the spacing at the value being stored
A floating-point representation can distinguish more closely spaced values near zero than it can at a large epoch count. NumPy's spacing function reports the gap to an adjacent representable value for the input's floating-point type. In the example, a float64 at 1,700,000,000,000,000,000 nanoseconds has a spacing of 256 nanoseconds. A difference of one nanosecond is smaller than that spacing.
import numpy as np
origin_ns = 1_700_000_000_000_000_000
ticks_ns = np.array(
[origin_ns + offset for offset in (0, 1, 100, 1000)],
dtype=np.int64,
)
absolute_float = ticks_ns.astype(np.float64)
assert np.spacing(absolute_float[0]) == 256.
assert (absolute_float - absolute_float[0]).tolist() == [
0., 0., 0., 1024.,
]
At this origin, the first three exact timestamps convert to the same float. The last represents an offset of 1,024 nanoseconds after conversion, instead of the intended 1,000. Different alignments between the original ticks and the floating-point grid can produce different rounding outcomes. A reported zero in the floating-point calculation is therefore not sufficient evidence of simultaneity.
Subtract the integer origin before converting
Integer arithmetic preserves the original differences in this fixture, where the operands and differences all fit in signed 64-bit integers. The resulting counts are small enough to represent exactly as float64. Scaling them by one billionth expresses the relative times in seconds to floating-point precision.
relative_ns = ticks_ns - ticks_ns[0]
relative_s = relative_ns.astype(np.float64) * 1e-9
assert relative_ns.tolist() == [0, 1, 100, 1000]
assert np.allclose(
relative_s, [0., 1e-9, 1e-7, 1e-6], atol=0., rtol=1e-15
)
For a run chart, store the reference tick alongside the relative times. For a duration test, compare the exact integer differences directly if its requirement is expressed in integer ticks. Keep the time unit in the field name or schema. A downstream job that mixes seconds and nanoseconds can apply a scale error even when it uses appropriate numeric types.
Converting to epoch seconds does not remove the issue by itself. For example, float32 at an absolute time of 1.7 billion seconds has a spacing of 128 seconds in the executed example. Float32 may still be suitable for a chosen relative time window. Test the size of the expected gap at the largest relative time the representation must carry. A floating-point timestamp field should have enough resolution for the decisions based on it.
Validate the integer range and the clock
Subtraction is exact in the example because the values are within range. A fixed-width integer calculation can overflow if it subtracts timestamps far enough apart. If the input type is unsigned, an out-of-order pair can also wrap when the intended difference is negative. Validate the input and differences against the schema before using fixed-width arithmetic. One option for a reader with arbitrary integer fields is to compute the difference in Python integers first and check the result before packing it into a bounded array.
Clock semantics are a separate dependency. Timestamps from two devices can have different origins or mismatched clock rates. Subtracting their integer representations preserves the recorded numbers without making the clocks comparable. Use the synchronization and rollover rules supplied with each device or logging system. For durations measured on one host, Python's monotonic_ns returns integer nanoseconds from a monotonic clock. The reading has no defined wall-clock origin, so a report uses differences rather than treating an individual value as a date.
A timestamp expressed in nanoseconds can still come from a clock with a coarser physical resolution. Check the source clock and record the resolution relevant to the test. Integer storage preserves what was recorded. It cannot recover differences that were lost at acquisition or by an earlier conversion.
Test the export and readback as well
A useful regression fixture contains at least two timestamps separated by less than the floating-point spacing at the stored magnitude. Write them through the same export path used for actual robot data, read them back, and compare their exact ticks. Then compare the decoded elapsed times against a known result. Confirm that any tool displaying the time axis either accepts the required precision or receives relative times with the reference stored separately. In particular, a data viewer that reads a large integer column as floating point can erase distinctions even though the original file still contains the exact text.
When a comma-separated export holds integer ticks as decimal text, parse that column directly as integers. A conversion through a float followed by int can produce a whole number that has already lost its low bits. This fixture makes that loss visible even for a single nanosecond.
text_tick = "1700000000000000001"
assert int(text_tick) == origin_ns + 1
assert int(float(text_tick)) == origin_ns
If the receiving system cannot represent large integer ticks exactly, a documented text field or a reference-plus-offset representation can preserve the recorded values.
Sources checked November 28, 2026
NumPy, numpy.spacing
https://numpy.org/doc/stable/reference/generated/numpy.spacing.html
Python 3.14 documentation, time
https://docs.python.org/3.14/library/time.html
Illustration. AI-generated concept showing that a short interval can be isolated before converting a pair of recorded timestamps.