-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPSDIR Review #145
Comments
On the 122 vs 128, in example of appendix C2 (and review of existing v3/v5 implementations) one simply modify the bits in the right position via some bit operations. Edit: I may add some text pointing to C.2 to state there is an example of how this bit modification is done so folks can see this. |
"just directly write the 10 bits of the timestamp" does not really make sense here unfortunately because the timestamp here is a sub-millisecond fraction. There is no canonical or natural way (as far as I know) to take the most significant 10 bits (or whatever bits) of a fractional number unless we dig deep into IEEE 754 floating-point numbers. Computationally, the example calculation is equivalent to the following integer arithmetics and is not so expensive as one might think from the example code that relies on floating-point math. # take submillisecond fraction from nanosecond timestamp
(456_700 << 12) // 1_000_000 |
The 2 extra bits can be populated with bits from a higher precision timestamp. If the system timestamp has a precision of 9 decimal digits, say "0.123456789", instead of the 7 digits of Windows, we can do this: >>> nanos = int(0.123456789 * 1_000_000_000)
>>> msecs = int(nanos / 1_000_000)
>>> rand1 = int(nanos % 1_000_000 / 100)
>>>
>>> print( nanos )
123456789
>>> print( msecs )
123
>>> print( rand1 )
4567 or this by avoiding divisions: >>> nanos = int(0.123456789 * 1_000_000_000)
>>> msecs = nanos >> 20
>>> rand1 = nanos >> 8 & 0xfff
>>>
>>> print( hex( nanos ) )
0x75bcd15
>>> print( hex( msecs ) )
0x75
>>> print( hex( rand1 ) )
0xbcd The first example is more intuitive, so it is preferred in my opinion. The second one is more accurate as it produces a 60-bit timestamp with 100-nanosecond precision and no loss due to IEEE 754 arithmetics. P.S.: However, I'm not sure anymore whether prescription of a formula or algorithm for shifting the bits should be included in the document. Perhaps it is beyond the scope of the document as it's hard to put this into words. |
I don't think we should include the |
The text was updated successfully, but these errors were encountered: