mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Prefer native Math.log2(), but support IE through internalized polyfill.
This commit is contained in:
parent
7e3d18f5d4
commit
2532f205a7
1 changed files with 5 additions and 2 deletions
|
@ -60,6 +60,10 @@ var Numerical = new function() {
|
||||||
var abs = Math.abs,
|
var abs = Math.abs,
|
||||||
sqrt = Math.sqrt,
|
sqrt = Math.sqrt,
|
||||||
pow = Math.pow,
|
pow = Math.pow,
|
||||||
|
// Fallback to polyfill:
|
||||||
|
log2 = Math.log2 || function(x) {
|
||||||
|
return Math.log(x) * Math.LOG2E;
|
||||||
|
},
|
||||||
// Constants
|
// Constants
|
||||||
EPSILON = 1e-12,
|
EPSILON = 1e-12,
|
||||||
MACHINE_EPSILON = 1.12e-16;
|
MACHINE_EPSILON = 1.12e-16;
|
||||||
|
@ -97,8 +101,7 @@ var Numerical = new function() {
|
||||||
function getNormalizationFactor(x) {
|
function getNormalizationFactor(x) {
|
||||||
// Normalization is done by scaling coefficients with a power of 2, so
|
// Normalization is done by scaling coefficients with a power of 2, so
|
||||||
// that all the bits in the mantissa remain unchanged.
|
// that all the bits in the mantissa remain unchanged.
|
||||||
return pow(2, -Math.floor(
|
return pow(2, -Math.round(log2(x || MACHINE_EPSILON)));
|
||||||
Math.log(x || MACHINE_EPSILON) * Math.LOG2E + 0.5));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return /** @lends Numerical */{
|
return /** @lends Numerical */{
|
||||||
|
|
Loading…
Reference in a new issue