aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-09-14 08:30:24 -0400
committerNick Mathewson <nickm@torproject.org>2018-09-14 08:35:06 -0400
commit4eabc6db47fe64b6757f7a5f0e651a41f02efca3 (patch)
tree735d90118add0aabf980a0aff50832bab587cfa6 /src/common
parent3ddfd5ff25b1319dee3a013c8dac02ff9121971e (diff)
downloadtor-4eabc6db47fe64b6757f7a5f0e651a41f02efca3.tar.gz
tor-4eabc6db47fe64b6757f7a5f0e651a41f02efca3.zip
Use a slightly more accurate formula for OSX 32-bit msec conversion
We use an optimized but less accurate formula for converting coarse time differences to milliseconds on 32-bit OSX platforms, so that we can avoid 64-bit division. The old numbers were off by 0.4%. The new numbers are off by .006%. This should make the unit tests a bit cleaner, and our tolerances a bit closer.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compat_time.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/common/compat_time.c b/src/common/compat_time.c
index 40847a8442..f92dc09c41 100644
--- a/src/common/compat_time.c
+++ b/src/common/compat_time.c
@@ -299,11 +299,11 @@ monotime_init_internal(void)
}
{
// For converting ticks to milliseconds in a 32-bit-friendly way, we
- // will first right-shift by 20, and then multiply by 20/19, since
- // (1<<20) * 19/20 is about 1e6. We precompute a new numerate and
+ // will first right-shift by 20, and then multiply by 2048/1953, since
+ // (1<<20) * 1953/2048 is about 1e6. We precompute a new numerator and
// denominator here to avoid multiple multiplies.
- mach_time_info_msec_cvt.numer = mach_time_info.numer * 20;
- mach_time_info_msec_cvt.denom = mach_time_info.denom * 19;
+ mach_time_info_msec_cvt.numer = mach_time_info.numer * 2048;
+ mach_time_info_msec_cvt.denom = mach_time_info.denom * 1953;
}
}