2 var $export = require('./_export')
3 , toInteger = require('./_to-integer')
4 , aNumberValue = require('./_a-number-value')
5 , repeat = require('./_string-repeat')
6 , $toFixed = 1..toFixed
8 , data = [0, 0, 0, 0, 0, 0]
9 , ERROR = 'Number.toFixed: incorrect invocation!'
12 var multiply = function(n, c){
21 var divide = function(n){
26 data[i] = floor(c / n);
30 var numToString = function(){
34 if(s !== '' || i === 0 || data[i] !== 0){
35 var t = String(data[i]);
36 s = s === '' ? t : s + repeat.call(ZERO, 7 - t.length) + t;
40 var pow = function(x, n, acc){
41 return n === 0 ? acc : n % 2 === 1 ? pow(x, n - 1, acc * x) : pow(x * x, n / 2, acc);
43 var log = function(x){
56 $export($export.P + $export.F * (!!$toFixed && (
57 0.00008.toFixed(3) !== '0.000' ||
58 0.9.toFixed(0) !== '1' ||
59 1.255.toFixed(2) !== '1.25' ||
60 1000000000000000128..toFixed(0) !== '1000000000000000128'
61 ) || !require('./_fails')(function(){
65 toFixed: function toFixed(fractionDigits){
66 var x = aNumberValue(this, ERROR)
67 , f = toInteger(fractionDigits)
71 if(f < 0 || f > 20)throw RangeError(ERROR);
72 if(x != x)return 'NaN';
73 if(x <= -1e21 || x >= 1e21)return String(x);
79 e = log(x * pow(2, 69, 1)) - 69;
80 z = e < 0 ? x * pow(2, -e, 1) : x / pow(2, e, 1);
81 z *= 0x10000000000000;
90 multiply(pow(10, j, 1), 0);
102 multiply(1 << -e, 0);
103 m = numToString() + repeat.call(ZERO, f);
108 m = s + (k <= f ? '0.' + repeat.call(ZERO, f - k) + m : m.slice(0, k - f) + '.' + m.slice(k - f));