[Git][NTPsec/ntpsec][master] Changed multiplications by powers of 2 to shifts

Ian Bruene gitlab at mg.gitlab.com
Wed Aug 23 19:57:06 UTC 2017


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
656daa25 by Ian Bruene at 2017-08-23T14:55:56-05:00
Changed multiplications by powers of 2 to shifts

- - - - -


1 changed file:

- pylib/packet.py


Changes:

=====================================
pylib/packet.py
=====================================
--- a/pylib/packet.py
+++ b/pylib/packet.py
@@ -454,20 +454,20 @@ class SyncPacket(Packet):
     def ntp_to_posix(t):
         "Scale from NTP time to POSIX time"
         # Note: assumes we're in the same NTP era as the transmitter...
-        return (t * 2**-32) - SyncPacket.UNIX_EPOCH
+        return (t >> 32) - SyncPacket.UNIX_EPOCH
 
     @staticmethod
     def posix_to_ntp(t):
         "Scale from POSIX time to NTP time"
         # Note: assumes we're in the same NTP era as the transmitter...
-        return int((t + SyncPacket.UNIX_EPOCH) * 2**32)
+        return int((t + SyncPacket.UNIX_EPOCH) << 32)
 
     def posixize(self):
         "Rescale all timestamps to POSIX time."
         if not self.rescaled:
             self.rescaled = True
-            self.root_delay *= 2**-16
-            self.root_dispersion *= 2**-16
+            self.root_delay >>= 16
+            self.root_dispersion >>= 16
             self.reference_timestamp = SyncPacket.ntp_to_posix(
                 self.reference_timestamp)
             self.origin_timestamp = SyncPacket.ntp_to_posix(



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/656daa25aaaf1e479bf86595e4be4c4ce9f127c7

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/656daa25aaaf1e479bf86595e4be4c4ce9f127c7
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170823/9b2f4115/attachment.html>


More information about the vc mailing list