mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-20 16:57:25 +03:00
64896d70b0
This reflects changes in Google's policy on JavaScript license headers, which should be smaller to avoid increasing the size of the binary unnecessarily. This also updates the company name from "Google, Inc" to "Google LLC". Change-Id: I3f8b9ed3700b6351f43173d50c94d35c333e82b4
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
/** @license
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
goog.provide('shaka.polyfill.MathRound');
|
|
|
|
goog.require('shaka.log');
|
|
goog.require('shaka.polyfill');
|
|
|
|
/**
|
|
* @summary A polyfill to patch math round bug on some browsers.
|
|
* @see https://stackoverflow.com/q/12830742
|
|
*/
|
|
shaka.polyfill.MathRound = class {
|
|
/**
|
|
* Install the polyfill if needed.
|
|
*/
|
|
static install() {
|
|
shaka.log.debug('mathRound.install');
|
|
|
|
const testNumber = shaka.polyfill.MathRound.MAX_ACCURATE_INPUT_ + 1;
|
|
if (Math.round(testNumber) != testNumber) {
|
|
shaka.log.debug('polyfill Math.round');
|
|
const originalMathRound = Math.round;
|
|
Math.round = (number) => {
|
|
let result = number;
|
|
// Due to the precision of JavaScript numbers, the number must be
|
|
// integer.
|
|
if (number <= shaka.polyfill.MathRound.MAX_ACCURATE_INPUT_) {
|
|
result = originalMathRound(number);
|
|
}
|
|
return result;
|
|
};
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
@const {number}
|
|
@private
|
|
*/
|
|
shaka.polyfill.MathRound.MAX_ACCURATE_INPUT_ = 0x10000000000000;
|
|
|
|
|
|
shaka.polyfill.register(shaka.polyfill.MathRound.install);
|