Pathologic was missing because of a .git folder inside.
[yaffs-website] / node_modules / core-js / modules / es6.number.to-fixed.js
1 'use strict';
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
7   , floor        = Math.floor
8   , data         = [0, 0, 0, 0, 0, 0]
9   , ERROR        = 'Number.toFixed: incorrect invocation!'
10   , ZERO         = '0';
11
12 var multiply = function(n, c){
13   var i  = -1
14     , c2 = c;
15   while(++i < 6){
16     c2 += n * data[i];
17     data[i] = c2 % 1e7;
18     c2 = floor(c2 / 1e7);
19   }
20 };
21 var divide = function(n){
22   var i = 6
23     , c = 0;
24   while(--i >= 0){
25     c += data[i];
26     data[i] = floor(c / n);
27     c = (c % n) * 1e7;
28   }
29 };
30 var numToString = function(){
31   var i = 6
32     , s = '';
33   while(--i >= 0){
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;
37     }
38   } return s;
39 };
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);
42 };
43 var log = function(x){
44   var n  = 0
45     , x2 = x;
46   while(x2 >= 4096){
47     n += 12;
48     x2 /= 4096;
49   }
50   while(x2 >= 2){
51     n  += 1;
52     x2 /= 2;
53   } return n;
54 };
55
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(){
62   // V8 ~ Android 4.3-
63   $toFixed.call({});
64 })), 'Number', {
65   toFixed: function toFixed(fractionDigits){
66     var x = aNumberValue(this, ERROR)
67       , f = toInteger(fractionDigits)
68       , s = ''
69       , m = ZERO
70       , e, z, j, k;
71     if(f < 0 || f > 20)throw RangeError(ERROR);
72     if(x != x)return 'NaN';
73     if(x <= -1e21 || x >= 1e21)return String(x);
74     if(x < 0){
75       s = '-';
76       x = -x;
77     }
78     if(x > 1e-21){
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;
82       e = 52 - e;
83       if(e > 0){
84         multiply(0, z);
85         j = f;
86         while(j >= 7){
87           multiply(1e7, 0);
88           j -= 7;
89         }
90         multiply(pow(10, j, 1), 0);
91         j = e - 1;
92         while(j >= 23){
93           divide(1 << 23);
94           j -= 23;
95         }
96         divide(1 << j);
97         multiply(1, 1);
98         divide(2);
99         m = numToString();
100       } else {
101         multiply(0, z);
102         multiply(1 << -e, 0);
103         m = numToString() + repeat.call(ZERO, f);
104       }
105     }
106     if(f > 0){
107       k = m.length;
108       m = s + (k <= f ? '0.' + repeat.call(ZERO, f - k) + m : m.slice(0, k - f) + '.' + m.slice(k - f));
109     } else {
110       m = s + m;
111     } return m;
112   }
113 });