Remove coercion method use.

This commit is contained in:
John-David Dalton
2017-03-13 20:49:45 -07:00
parent 2f281c68b0
commit bb7c959479
33 changed files with 59 additions and 194 deletions

View File

@@ -1,7 +1,3 @@
import toInteger from '../toInteger.js'
import toNumber from '../toNumber.js'
import toString from '../toString.js'
/**
* Creates a function like `round`.
*
@@ -12,15 +8,14 @@ import toString from '../toString.js'
function createRound(methodName) {
const func = Math[methodName]
return (number, precision) => {
number = toNumber(number)
precision = precision == null ? 0 : Math.min(toInteger(precision), 292)
precision = precision == null ? 0 : Math.min(precision, 292)
if (precision) {
// Shift with exponential notation to avoid floating-point issues.
// See [MDN](https://mdn.io/round#Examples) for more details.
let pair = `${ toString(number) }e`.split('e')
let pair = `${ number }e`.split('e')
const value = func(`${ pair[0] }e${ +pair[1] + precision }`)
pair = `${ toString(value) }e`.split('e')
pair = `${ value }e`.split('e')
return +`${ pair[0] }e${ +pair[1] - precision }`
}
return func(number)