File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,9 @@ module.exports = function frexp (arg) {
44
44
45
45
if ( arg !== 0 && Number . isFinite ( arg ) ) {
46
46
const absArg = Math . abs ( arg )
47
- let exp = Math . max ( - 1023 , Math . floor ( Math . log2 ( absArg ) ) + 1 )
47
+ // Math.log2 was introduced in ES2015, use it when available
48
+ const log2 = Math . log2 || function log2 ( n ) { return Math . log ( n ) * Math . LOG2E }
49
+ let exp = Math . max ( - 1023 , Math . floor ( log2 ( absArg ) ) + 1 )
48
50
let x = absArg * Math . pow ( 2 , - exp )
49
51
50
52
// These while loops compensate for rounding errors that sometimes occur because of ECMAScript's Math.log2's undefined precision
@@ -58,7 +60,9 @@ module.exports = function frexp (arg) {
58
60
exp ++
59
61
}
60
62
61
- x *= Math . sign ( arg )
63
+ if ( arg < 0 ) {
64
+ x = - x
65
+ }
62
66
result [ 0 ] = x
63
67
result [ 1 ] = exp
64
68
}
You can’t perform that action at this time.
0 commit comments