mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -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,
|
||||
sqrt = Math.sqrt,
|
||||
pow = Math.pow,
|
||||
// Fallback to polyfill:
|
||||
log2 = Math.log2 || function(x) {
|
||||
return Math.log(x) * Math.LOG2E;
|
||||
},
|
||||
// Constants
|
||||
EPSILON = 1e-12,
|
||||
MACHINE_EPSILON = 1.12e-16;
|
||||
|
@ -97,8 +101,7 @@ var Numerical = new function() {
|
|||
function getNormalizationFactor(x) {
|
||||
// Normalization is done by scaling coefficients with a power of 2, so
|
||||
// that all the bits in the mantissa remain unchanged.
|
||||
return pow(2, -Math.floor(
|
||||
Math.log(x || MACHINE_EPSILON) * Math.LOG2E + 0.5));
|
||||
return pow(2, -Math.round(log2(x || MACHINE_EPSILON)));
|
||||
}
|
||||
|
||||
return /** @lends Numerical */{
|
||||
|
|
Loading…
Reference in a new issue