mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-15 16:06:41 +03:00
5f8e958ef3
Due do rounding errors the progress events were fired way too early (especially the complete event on longer videos). This changes use float comparison to mitigate the issue. Further improvements (video with start time, seek handling) will be added in follow up PRs. Co-authored-by: Álvaro Velad Galván <ladvan91@hotmail.com>
38 lines
712 B
JavaScript
38 lines
712 B
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
goog.provide('shaka.util.NumberUtils');
|
|
|
|
|
|
shaka.util.NumberUtils = class {
|
|
/**
|
|
* Compare two float numbers, taking a configurable tolerance margin into
|
|
* account.
|
|
*
|
|
* @param {number} a
|
|
* @param {number} b
|
|
* @param {number=} tolerance
|
|
* @return {boolean}
|
|
*/
|
|
static isFloatEqual(a, b, tolerance = Number.EPSILON) {
|
|
if (a === b) {
|
|
return true;
|
|
}
|
|
|
|
const error = Math.abs(a - b);
|
|
|
|
if (error <= tolerance) {
|
|
return true;
|
|
}
|
|
|
|
if (tolerance !== Number.EPSILON) {
|
|
return Math.abs(error - tolerance) <= Number.EPSILON;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
};
|