Bug 1438953 Increase the epsilon on timer reduction tests r=froydnj

In Javascript, we re-clamp timers to ensure they stay the same. Because of double imprecision
sometimes they don't stay the same, and are clamped downwards. If that happens we detect it,
and if we were originally off by an epsilon from a clamped value, we accept the value in the
name of double imprecision.

However, the epsilons were originally chosen somewhat arbitrarily. They worked for small
numbers, where imprecision from doubles were very small. But large doubles have much less
precise fractional parts. So the epsilons were too large for large numbers where the
imprecision was larger.

MozReview-Commit-ID: HnYYo4cuv96

--HG--
extra : rebase_source : 3a1d70e801fe7b8e1a8b2c191854db3db11751a9
This commit is contained in:
Tom Ritter 2018-02-16 12:31:55 -06:00
Родитель 3a72c74e9c
Коммит aed0c1a052
4 изменённых файлов: 36 добавлений и 16 удалений

Просмотреть файл

@ -37,10 +37,15 @@ let isRounded = (x, expectedPrecision) => {
return true; return true;
// When we're diving by non-whole numbers, we may not get perfect // When we're diving by non-whole numbers, we may not get perfect
// multiplication/division because of floating points // multiplication/division because of floating points.
if (Math.abs(rounded - x + expectedPrecision) < .0000001) { // When dealing with ms since epoch, a double's precision is on the order
// of 1/5 of a microsecond, so we use a value a little higher than that as
// our epsilon.
// To be clear, this error is introduced in our re-calculation of 'rounded'
// above in JavaScript.
if (Math.abs(rounded - x + expectedPrecision) < .0005) {
return true; return true;
} else if (Math.abs(rounded - x) < .0000001) { } else if (Math.abs(rounded - x) < .0005) {
return true; return true;
} }

Просмотреть файл

@ -17,10 +17,15 @@ let isRounded = (x, expectedPrecision) => {
return true; return true;
// When we're diving by non-whole numbers, we may not get perfect // When we're diving by non-whole numbers, we may not get perfect
// multiplication/division because of floating points // multiplication/division because of floating points.
if (Math.abs(rounded - x + expectedPrecision) < .0000001) { // When dealing with ms since epoch, a double's precision is on the order
// of 1/5 of a microsecond, so we use a value a little higher than that as
// our epsilon.
// To be clear, this error is introduced in our re-calculation of 'rounded'
// above in JavaScript.
if (Math.abs(rounded - x + expectedPrecision) < .0005) {
return true; return true;
} else if (Math.abs(rounded - x) < .0000001) { } else if (Math.abs(rounded - x) < .0005) {
return true; return true;
} }

Просмотреть файл

@ -36,10 +36,15 @@
return true; return true;
// When we're diving by non-whole numbers, we may not get perfect // When we're diving by non-whole numbers, we may not get perfect
// multiplication/division because of floating points // multiplication/division because of floating points.
if (Math.abs(rounded - x + expectedPrecision) < .0000001) { // When dealing with ms since epoch, a double's precision is on the order
// of 1/5 of a microsecond, so we use a value a little higher than that as
// our epsilon.
// To be clear, this error is introduced in our re-calculation of 'rounded'
// above in JavaScript.
if (Math.abs(rounded - x + expectedPrecision) < .0005) {
return true; return true;
} else if (Math.abs(rounded - x) < .0000001) { } else if (Math.abs(rounded - x) < .0005) {
return true; return true;
} }

Просмотреть файл

@ -51,10 +51,15 @@ https://trac.torproject.org/projects/tor/ticket/1517
return true; return true;
// When we're diving by non-whole numbers, we may not get perfect // When we're diving by non-whole numbers, we may not get perfect
// multiplication/division because of floating points // multiplication/division because of floating points.
if (Math.abs(rounded - x + expectedPrecision) < .0000001) { // When dealing with ms since epoch, a double's precision is on the order
// of 1/5 of a microsecond, so we use a value a little higher than that as
// our epsilon.
// To be clear, this error is introduced in our re-calculation of 'rounded'
// above in JavaScript.
if (Math.abs(rounded - x + expectedPrecision) < .0005) {
return true; return true;
} else if (Math.abs(rounded - x) < .0000001) { } else if (Math.abs(rounded - x) < .0005) {
return true; return true;
} }