Code coverage report for decimal.js\decimal.js

Statements: 96.35% (1161 / 1205)      Branches: 96.69% (1051 / 1087)      Functions: 89.87% (71 / 79)      Lines: 96.74% (1158 / 1197)      Ignored: none     

All files » decimal.js\ » decimal.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064  1                         1                                                                                     1 3952   3952 1407     3952                 1   151                       1 80751                   80751 102     80649 80649     80649 13546       67103 1517     65586     65586 1264       64322 40244       24078       31988 1329         22749               1 32     32 29   29     27     29 11       32                                                 1 5039   5039                   1 10000   10000   10000                     1 23426   23426                   1   500                 1   130                 1 180   180                 1 10026 10026   10026               1   10               1   14               1   30               1   10               1   10               1 10169   10169                 1 27 27   27                                                                     1 840               840 500 500   340 340 340     340   12   328   828     828   6             822                     822 822 822   822   822   537     537   285       822                                   822   125 143 143   143 52   52     52   91     143   143     95 34     95       822   822                                                 1 54817         54817 54817 54817     54817   50       54767 1948   1948     52819             52819     20678   31       20647     878         878       51910 51910     51910   15899 8069 8069 8069   7830 7830     15899 7673                 15899 5462 5462     15899 15899 15899       36011 2213     36011   50687 31805   31805           51910 9675 9675             51910   15129       51910   180314   48241 48241 48241   180314       51910     51910   51910     2498     2498     51910     51910 51910   51910                                                       1 1000         1000 1000 1000 1000           1000   128         872   872       12 12 12 12   860     872 872   872                 1   500                 1 400 400   400                                                 1 129897         129897 129897 129897     129897   51       129846 7854   7854     121992             121992     40891     1250       39641     5811   5811       114931     114931   53801 12867 12867 12867   40934 40934 40934     53801 13099       53801 5642 5642     53801 53801       114931 19807       114931 617042     114931 906 906       114931       114931     114931 114931   114931                   1 32     32   20             32 29   29 5       32                 1 10002     10002                               1 4000                 4000   144     3856     3856           3856 803   803 411     803 803   803     803 803     803   3053     3856     3856 6156 6156   6156   3873           3873           19 5   5 2   2     17 17             3854     2890 2890     3854       3856   3856                                                 1 205768                 205768   205768     205768     4822                                   200946 200946 200946   200946     73042 73042     200946     200946 598844   598844 4787795 4787795 4787795   598844     200946 63944 137002     137002       200946 200946     200946 200946   200946                                     1 2000 2000   2000                                           1 700   700                                                 1 1820           1820 894 873       1799   1799 947   852       852     386 6     380 22       1799 1799   1799                                               1 116   116 9     107                       107 21     107 104 104   104 205     104 18     104 3       107                                       1 1500                 1500         1500 1500     1500                                     1211     1477 1477 1477 1477   1477 30860 30860   30860   1477   29383 29383   29383 29383   29383 29383     1477 1477 1477 1477     1477         1477 1477   1477                                                     1 107     107   107 18 18   89 89 89       107     90   85 76 76 76 76   9         17     14 12   14     107               1 32     32                                                                                                     1 1400                   1386     141     1245 1245     1245   16     1229     1229 86   1143 1143     1143 2             1141 743   743   10         398   398               398               398   15     383 383                 383     383     383           383 35     35           35 19       383 383 383     1116       1204                                             1 700   700                                     1 20002     20002   20002                                   1 129600           129600 793     128807   76750   52057     52057     2228 2228     49829   44522     8457   36065 9653         5307   5307 933     4374   964       51093   9900   9864     9864               36         51865               1   100                   1   10817                                                                       1 240368         240368 1238230   1238230 196247     1238230       240368   240368                                     1 2221     2221   2221     2221 145 145   2076 2076     2221 2221   2221   1727   820 255 565 301     820   907           494   293 76 217 70 147 57     293   201           2221             1 24089   24089                   1 29108   29108                           1             1 19954           19954 327551 327551   327551   5362675   4525459 299304   4525459 4525459         19954     1 19565         19565 19565       19565 389 389 389             389 389       19565 19565     19565   19565   155     19410 19021   389 389     389 389 389 389 389       19410 19410 19410   19410         139     139 28   28 1 1       19271       19410     19410     19410     36   36       19374   19374     1958   17416 283         19410               1     1 310176       310176 1761916 1761916 1761916     310176 256748     310176     1 733165   733165 244866     488299   607877 487941   487941         733165     1 260078     260078 1837885 1837885 1837885       260078       1 107488               107488   1407                   106081 389 389   105692 105692 105692     106081 106081 106081 106081       106081   106081 24988     106081 4933 4933 101148 42035   59113     106081 374 374       105707 105707     105707 61675 61675 61675     61675 388471 388471 388471     61675           44032   44032 42014 42014 42014 42014     44032 44032 44032     44032   44032 44032 44032   44032 21068     44032 282755     282755     282755     236322   236322 234544       236322                       236322   226148 722       226148 226148 226148     226148     226148 11771     11771             10174 109   10174   236322   236322 8774       236322     236322 224262     224262     224262 11985     11985       236322   46433 12 12       282755     282755 282387   368 368         44032       105707 55656         106081 389 389       105692 105692   105692     106081                                                                 1 918                   918   54         864                               446 446   418     864     864     3269 3269             864 864   864 864   864 12993 12993 12993   12993   887   887 16355                       887   469 23 23 23 23     446     418   418     12129                         1 78917         78917 76795   2122     2122     78917 78917                 78917     77731   77731 73297     77731       1186     1186 189     189 189         997 31     31   31 28       966   966 500 466 390           1186   572       78917       1 1529     1529     1505     1505     1529             1   766 349               349 349   349               1 1132   1132   4152 2429   4152   4152   1132   3020   1132   1132                               1 2297                     2297   11     2286 489 489   1797     2286   2286 2286   2286                             2248 3832 3832 3832 3832     2248   2248 1297 1297   951                 38   38       38       38   38       2248               2248 2248 2248   2248 31153 31153   31153   2277             2277   2135       2135         2277                       2277   503 29 29 29 29     474     1774   1774       28905 28905               1 258409       258409     253981   38                           253943   253943     253943 5803 5803 5803     5803   248140   248140   37183     10   10 10 10 10     37173     210957     210957     210957       210957       210957       216770                   216770             216770 1467   1467     131     131 131       1336     1467         215303 71968 71968 71968   143335 143335       143335       215303   29293     43277     3507   3507   3507     3507 253   253 35       3507   39770   39770   25786     13984 13984           215303     256904     98148     1     98147     1       256904       1                                                                                                                                                                                                                             1 763         763       3       757   582 556         26         743   580 554         26         729   47 43         4         725   45 41         4         721   47 41         6         715   47 41         6         709   75 56 56       19         695   33 14       19         681   28 14         14         667   2 2               667                                     1                                   1                         1           1 121     121 52     121   121 288   288 7   7 281 99       121                   58                 63           1 1       1 382925   382925     194468     382925   382925     367559                 15366   327     15039   15039   15039   9751   9719     9719     9719     9701   56             56   9701   18     6 3           32     15     5288     15019     5239     5239     971     334   881   5149   5149         377339 153728       377339     83975 4891   83975 83975   293364     218720       377339     377339   377339   377339 359886     359886     2     359886 359886           359886   359886 45990       359886   155630 138720     155630 624527     155630 155630   204256     359886   359886   359886     207030     16     207014     8           17453   377339   377339                       1                     1 10000           10000 5059   4937     9996   9996                                                                                                           9996   9996 11955       9996 9996     9996 8521 8521       9996 206       9996 610   9386     9386           9386 55344 55344       9386 897       9996 9996   9996                                                                   1                                                 1                   1 927960     927960               927960     927960   545046 545034 545034 545034 545034   545034 12   1   11       382925                               10                                     10                                       10       10       10       10       10     10     10     10                         10   10                 10 10 10 10 10 10 10 10 10     10                             10 10 10 10 10 10 10 10 10 10   10 8     10     1               1             1 1   1   1 1                                  
/*! decimal.js v4.0.1 https://github.com/MikeMcl/decimal.js/LICENCE */
;(function (global) {
    'use strict';
 
 
    /*
     *  decimal.js v4.0.1
     *  An arbitrary-precision Decimal type for JavaScript.
     *  https://github.com/MikeMcl/decimal.js
     *  Copyright (c) 2014 Michael Mclaughlin <M8ch88l@gmail.com>
     *  MIT Expat Licence
     */
 
 
    var convertBase, decimal, noConflict,
        crypto = global['crypto'],
        external = true,
        id = 0,
        mathfloor = Math.floor,
        mathpow = Math.pow,
        outOfRange,
        toString = Object.prototype.toString,
        BASE = 1e7,
        LOGBASE = 7,
        NUMERALS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_',
        P = {},
 
        /*
         The maximum exponent magnitude.
         The limit on the value of toExpNeg, toExpPos, minE and maxE.
         */
        EXP_LIMIT = 9e15,                      // 0 to 9e15
 
        /*
         The limit on the value of precision, and on the argument to toDecimalPlaces,
         toExponential, toFixed, toFormat, toPrecision and toSignificantDigits.
         */
        MAX_DIGITS = 1E9,                      // 0 to 1e+9
 
        /*
         To decide whether or not to calculate x.pow(integer y) using the 'exponentiation by
         squaring' algorithm or by exp(y*ln(x)), the number of significant digits of x is multiplied
         by y. If this number is less than INT_POW_LIMIT then the former algorithm is used.
         */
        INT_POW_LIMIT = 3000,                  // 0 to 5000
 
        // The natural logarithm of 10 (1025 digits).
        LN10 = '2.3025850929940456840179914546843642076011014886287729760333279009675726096773524802359972050895982983419677840422862486334095254650828067566662873690987816894829072083255546808437998948262331985283935053089653777326288461633662222876982198867465436674744042432743651550489343149393914796194044002221051017141748003688084012647080685567743216228355220114804663715659121373450747856947683463616792101806445070648000277502684916746550586856935673420670581136429224554405758925724208241314695689016758940256776311356919292033376587141660230105703089634572075440370847469940168269282808481184289314848524948644871927809676271275775397027668605952496716674183485704422507197965004714951050492214776567636938662976979522110718264549734772662425709429322582798502585509785265383207606726317164309505995087807523710333101197857547331541421808427543863591778117054309827482385045648019095610299291824318237525357709750539565187697510374970888692180205189339507238539205144634197265287286965110862571492198849978748873771345686209167058';
 
 
    // Decimal prototype methods
 
 
    /*
     * Return a new Decimal whose value is the absolute value of this Decimal.
     *
     */
    P['absoluteValue'] = P['abs'] = function () {
        var x = new this['constructor'](this);
 
        if ( x['s'] < 0 ) {
            x['s'] = 1;
        }
 
        return rnd(x);
    };
 
 
    /*
     * Return a new Decimal whose value is the value of this Decimal rounded to a whole number in
     * the direction of positive Infinity.
     *
     */
    P['ceil'] = function () {
 
        return rnd( new this['constructor'](this), this['e'] + 1, 2 );
    };
 
 
    /*
     * Return
     *   1    if the value of this Decimal is greater than the value of Decimal(y, b),
     *  -1    if the value of this Decimal is less than the value of Decimal(y, b),
     *   0    if they have the same value,
     *  null  if the value of either Decimal is NaN.
     *
     */
    P['comparedTo'] = P['cmp'] = function ( y, b ) {
        var a,
            x = this,
            xc = x['c'],
            yc = ( id = -id, y = new x['constructor']( y, b ), y['c'] ),
            i = x['s'],
            j = y['s'],
            k = x['e'],
            l = y['e'];
 
        // Either NaN?
        if ( !i || !j ) {
            return null;
        }
 
        a = xc && !xc[0];
        b = yc && !yc[0];
 
        // Either zero?
        if ( a || b ) {
            return a ? b ? 0 : -j : i;
        }
 
        // Signs differ?
        if ( i != j ) {
            return i;
        }
 
        a = i < 0;
 
        // Either Infinity?
        if ( !xc || !yc ) {
            return k == l ? 0 : !xc ^ a ? 1 : -1;
        }
 
        // Compare exponents.
        if ( k != l ) {
            return k > l ^ a ? 1 : -1;
        }
 
        // Compare digit by digit.
        for ( i = -1,
              j = ( k = xc.length ) < ( l = yc.length ) ? k : l;
              ++i < j; ) {
 
            if ( xc[i] != yc[i] ) {
                return xc[i] > yc[i] ^ a ? 1 : -1;
            }
        }
 
        // Compare lengths.
        return k == l ? 0 : k > l ^ a ? 1 : -1;
    };
 
 
    /*
     * Return the number of decimal places of the value of this Decimal.
     *
     */
     P['decimalPlaces'] = P['dp'] = function () {
        var c, v,
            n = null;
 
        if ( c = this['c'] ) {
            n = ( ( v = c.length - 1 ) - mathfloor( this['e'] / LOGBASE ) ) * LOGBASE;
 
            if ( v = c[v] ) {
 
                // Subtract the number of trailing zeros of the last number.
                for ( ; v % 10 == 0; v /= 10, n-- );
            }
 
            if ( n < 0 ) {
                n = 0;
            }
        }
 
        return n;
    };
 
 
    /*
     *  n / 0 = I
     *  n / N = N
     *  n / I = 0
     *  0 / n = 0
     *  0 / 0 = N
     *  0 / N = N
     *  0 / I = 0
     *  N / n = N
     *  N / 0 = N
     *  N / N = N
     *  N / I = N
     *  I / n = I
     *  I / 0 = I
     *  I / N = N
     *  I / I = N
     *
     * Return a new Decimal whose value is the value of this Decimal divided by Decimal(y, b),
     * rounded to precision significant digits using rounding mode rounding.
     *
     */
    P['dividedBy'] = P['div'] = function ( y, b ) {
        id = 2;
 
        return div( this, new this['constructor']( y, b ) );
    };
 
 
    /*
     * Return a new Decimal whose value is the integer part of dividing the value of this Decimal by
     * the value of Decimal(y, b), rounded to precision significant digits using rounding mode
     * rounding.
     *
     */
    P['dividedToIntegerBy'] = P['divToInt'] = function ( y, b ) {
        var x = this,
            Decimal = x['constructor'];
        id = 18;
 
        return rnd(
          div( x, new Decimal( y, b ), 0, 1, 1 ), Decimal['precision'], Decimal['rounding']
        );
    };
 
 
    /*
     * Return true if the value of this Decimal is equal to the value of Decimal(n, b), otherwise
     * return false.
     *
     */
    P['equals'] = P['eq'] = function ( n, b ) {
        id = 3;
 
        return this['cmp']( n, b ) === 0;
    };
 
 
    /*
     * Return a new Decimal whose value is the exponential of the value of this Decimal, i.e. the
     * base e raised to the power the value of this Decimal, rounded to precision significant digits
     * using rounding mode rounding.
     *
     */
    P['exponential'] = P['exp'] = function () {
 
        return exp(this);
    };
 
 
    /*
     * Return a new Decimal whose value is the value of this Decimal rounded to a whole number in
     * the direction of negative Infinity.
     *
     */
    P['floor'] = function () {
 
        return rnd( new this['constructor'](this), this['e'] + 1, 3 );
    };
 
 
    /*
     * Return true if the value of this Decimal is greater than the value of Decimal(n, b), otherwise
     * return false.
     *
     */
    P['greaterThan'] = P['gt'] = function ( n, b ) {
        id = 4;
 
        return this['cmp']( n, b ) > 0;
    };
 
 
    /*
     * Return true if the value of this Decimal is greater than or equal to the value of
     * Decimal(n, b), otherwise return false.
     *
     */
    P['greaterThanOrEqualTo'] = P['gte'] = function ( n, b ) {
        id = 5;
        b = this['cmp']( n, b );
 
        return b == 1 || b === 0;
    };
 
 
    /*
     * Return true if the value of this Decimal is a finite number, otherwise return false.
     *
     */
    P['isFinite'] = function () {
 
        return !!this['c'];
    };
 
 
    /*
     * Return true if the value of this Decimal is an integer, otherwise return false.
     *
     */
    P['isInteger'] = P['isInt'] = function () {
 
        return !!this['c'] && mathfloor( this['e'] / LOGBASE ) > this['c'].length - 2;
    };
 
 
    /*
     * Return true if the value of this Decimal is NaN, otherwise return false.
     *
     */
    P['isNaN'] = function () {
 
        return !this['s'];
    };
 
 
    /*
     * Return true if the value of this Decimal is negative, otherwise return false.
     *
     */
    P['isNegative'] = P['isNeg'] = function () {
 
        return this['s'] < 0;
    };
 
 
    /*
     * Return true if the value of this Decimal is 0 or -0, otherwise return false.
     *
     */
    P['isZero'] = function () {
 
        return !!this['c'] && this['c'][0] == 0;
    };
 
 
    /*
     * Return true if the value of this Decimal is less than Decimal(n, b), otherwise return false.
     *
     */
    P['lessThan'] = P['lt'] = function ( n, b ) {
        id = 6;
 
        return this['cmp']( n, b ) < 0;
    };
 
 
    /*
     * Return true if the value of this Decimal is less than or equal to Decimal(n, b), otherwise
     * return false.
     *
     */
    P['lessThanOrEqualTo'] = P['lte'] = function ( n, b ) {
        id = 7;
        b = this['cmp']( n, b );
 
        return b == -1 || b === 0;
    };
 
 
    /*
     * Return the logarithm of the value of this Decimal to the specified base, rounded
     * to precision significant digits using rounding mode rounding.
     *
     * If no base is specified, return log[10](arg).
     *
     * log[base](arg) = ln(arg) / ln(base)
     *
     * The result will always be correctly rounded if the base of the log is 2 or 10, and
     * 'almost always' if not:
     *
     * Depending on the rounding mode, the result may be incorrectly rounded if the first fifteen
     * rounding digits are [49]99999999999999 or [50]00000000000000. In that case, the maximum error
     * between the result and the correctly rounded result will be one ulp (unit in the last place).
     *
     * log[-b](a)       = NaN
     * log[0](a)        = NaN
     * log[1](a)        = NaN
     * log[NaN](a)      = NaN
     * log[Infinity](a) = NaN
     * log[b](0)        = -Infinity
     * log[b](-0)       = -Infinity
     * log[b](-a)       = NaN
     * log[b](1)        = 0
     * log[b](Infinity) = Infinity
     * log[b](NaN)      = NaN
     *
     * [base] {number|string|Decimal} The base of the logarithm.
     * [b] {number} The base of base.
     *
     */
    P['logarithm'] = P['log'] = function ( base, b ) {
        var base10, c, denom, i, inf, num, sd, sd10, r,
            arg = this,
            Decimal = arg['constructor'],
            pr = Decimal['precision'],
            rm = Decimal['rounding'],
            guard = 5;
 
        // Default base is 10.
        if ( base == null ) {
            base = new Decimal(10);
            base10 = true;
        } else {
            id = 15;
            base = new Decimal( base, b );
            c = base['c'];
 
            // If base < 0 or +-Infinity/NaN or 0 or 1.
            if ( base['s'] < 0 || !c || !c[0] || !base['e'] && c[0] == 1 && c.length == 1 ) {
 
                return new Decimal(NaN);
            }
            base10 = base['eq'](10);
        }
        c = arg['c'];
 
        // If arg < 0 or +-Infinity/NaN or 0 or 1.
        if ( arg['s'] < 0 || !c || !c[0] || !arg['e'] && c[0] == 1 && c.length == 1 ) {
 
            return new Decimal( c && !c[0] ? -1 / 0 : arg['s'] != 1 ? NaN : c ? 0 : 1 / 0 );
        }
 
        /*
          The result will have an infinite decimal expansion if base is 10 and arg is not an
          integer power of 10...
         */
        inf = base10 && ( i = c[0], c.length > 1 || i != 1 && i != 10 &&
          i != 1e2 && i != 1e3 && i != 1e4 && i != 1e5 && i != 1e6 );
            /*
            // or if base last digit's evenness is not the same as arg last digit's evenness...
            // (FAILS when e.g. base.c[0] = 10 and c[0] = 1)
            || ( base['c'][ base['c'].length - 1 ] & 1 ) != ( c[ c.length - 1 ] & 1 )
              // or if base is 2 and there is more than one 1 in arg in base 2.
              // (SLOWS the method down significantly)
              || base['eq'](2) && arg.toString(2).replace( /[^1]+/g, '' ) != '1';
             */
 
        external = false;
        sd = pr + guard;
        sd10 = sd + 10;
 
        num = ln( arg, sd );
 
        if (base10) {
 
            Iif ( sd10 > LN10.length ) {
                ifExceptionsThrow( Decimal, 1, sd10, 'log' );
            }
            denom = new Decimal( LN10.slice( 0, sd10 ) );
        } else {
            denom = ln( base, sd );
        }
 
        // The result will have 5 rounding digits.
        r = div( num, denom, sd, 1 );
 
        /*
         If at a rounding boundary, i.e. the result's rounding digits are [49]9999 or [50]0000,
         calculate 10 further digits.
 
         If the result is known to have an infinite decimal expansion, repeat this until it is
         clear that the result is above or below the boundary. Otherwise, if after calculating
         the 10 further digits, the last 14 are nines, round up and assume the result is exact.
         Also assume the result is exact if the last 14 are zero.
 
         Example of a result that will be incorrectly rounded:
         log[1048576](4503599627370502) = 2.60000000000000009610279511444746...
         The above result correctly rounded using ROUND_CEIL to 1 decimal place should be 2.7,
         but it will be given as 2.6 as there are 15 zeros immediately after the requested
         decimal place, so the exact result would be assumed to be 2.6, which rounded using
         ROUND_CEIL to 1 decimal place is still 2.6.
         */
        if ( checkRoundingDigits( r['c'], i = pr, rm ) ) {
 
            do {
                sd += 10;
                num = ln( arg, sd );
 
                if (base10) {
                    sd10 = sd + 10;
 
                    Iif ( sd10 > LN10.length ) {
                        ifExceptionsThrow( Decimal, 1, sd10, 'log' );
                    }
                    denom = new Decimal( LN10.slice( 0, sd10 ) );
                } else {
                    denom = ln( base, sd );
                }
 
                r = div( num, denom, sd, 1 );
 
                if ( !inf ) {
 
                    // Check for 14 nines from the 2nd rounding digit, as the first may be 4.
                    if ( +coefficientToString( r['c'] ).slice( i + 1, i + 15 ) + 1 == 1e14 ) {
                        r = rnd( r, pr + 1, 0 );
                    }
 
                    break;
                }
            } while ( checkRoundingDigits( r['c'], i += 10, rm ) );
        }
        external = true;
 
        return rnd( r, pr, rm );
    };
 
 
    /*
     *  n - 0 = n
     *  n - N = N
     *  n - I = -I
     *  0 - n = -n
     *  0 - 0 = 0
     *  0 - N = N
     *  0 - I = -I
     *  N - n = N
     *  N - 0 = N
     *  N - N = N
     *  N - I = N
     *  I - n = I
     *  I - 0 = I
     *  I - N = N
     *  I - I = N
     *
     * Return a new Decimal whose value is the value of this Decimal minus Decimal(y, b), rounded
     * to precision significant digits using rounding mode rounding.
     *
     */
    P['minus'] = function ( y, b ) {
        var t, i, j, xLTy,
            x = this,
            Decimal = x['constructor'],
            a = x['s'];
 
        id = 8;
        y = new Decimal( y, b );
        b = y['s'];
 
        // Either NaN?
        if ( !a || !b ) {
 
            return new Decimal(NaN);
        }
 
        // Signs differ?
        if ( a != b ) {
            y['s'] = -b;
 
            return x['plus'](y);
        }
 
        var xc = x['c'],
            yc = y['c'],
            e = mathfloor( y['e'] / LOGBASE ),
            k = mathfloor( x['e'] / LOGBASE ),
            pr = Decimal['precision'],
            rm = Decimal['rounding'];
 
        if ( !k || !e ) {
 
            // Either Infinity?
            if ( !xc || !yc ) {
 
                return xc ? ( y['s'] = -b, y ) : new Decimal( yc ? x : NaN );
            }
 
            // Either zero?
            if ( !xc[0] || !yc[0] ) {
 
                // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
                x = yc[0] ? ( y['s'] = -b, y ) : new Decimal( xc[0] ? x :
 
                  // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
                  rm == 3 ? -0 : 0 );
 
                return external ? rnd( x, pr, rm ) : x;
            }
        }
 
        xc = xc.slice();
        i = xc.length;
 
        // Determine which is the bigger number. Prepend zeros to equalise exponents.
        if ( a = k - e ) {
 
            if ( xLTy = a < 0 ) {
                a = -a;
                t = xc;
                i = yc.length;
            } else {
                e = k;
                t = yc;
            }
 
            if ( ( k = Math.ceil( pr / LOGBASE ) ) > i ) {
                i = k;
            }
 
            /*
             Numbers with massively different exponents would result in a massive number of
             zeros needing to be prepended, but this can be avoided while still ensuring correct
             rounding by limiting the number of zeros to max( pr, i ) + 2, where pr is precision and
             i is the length of the coefficient of whichever is greater, x or y.
             */
            if ( a > ( i += 2 ) ) {
                a = i;
                t.length = 1;
            }
 
            t.reverse();
            for ( b = a; b--; t.push(0) );
            t.reverse();
        } else {
            // Exponents equal. Check digits.
 
            if ( xLTy = i < ( j = yc.length ) ) {
                j = i;
            }
 
            for ( a = b = 0; b < j; b++ ) {
 
                if ( xc[b] != yc[b] ) {
                    xLTy = xc[b] < yc[b];
 
                    break;
                }
            }
        }
 
        // x < y? Point xc to the array of the bigger number.
        if ( xLTy ) {
            t = xc, xc = yc, yc = t;
            y['s'] = -y['s'];
        }
 
        /*
         Append zeros to xc if shorter. No need to add zeros to yc if shorter as subtraction only
         needs to start at yc length.
         */
        if ( ( b = -( ( j = xc.length ) - yc.length ) ) > 0 ) {
 
            for ( ; b--; xc[j++] = 0 );
        }
 
        // Subtract yc from xc.
        for ( k = BASE - 1, b = yc.length; b > a; ) {
 
            if ( xc[--b] < yc[b] ) {
 
                for ( i = b; i && !xc[--i]; xc[i] = k );
                --xc[i];
                xc[b] += BASE;
            }
            xc[b] -= yc[b];
        }
 
        // Remove trailing zeros.
        for ( ; xc[--j] == 0; xc.pop() );
 
        // Remove leading zeros and adjust exponent accordingly.
        for ( ; xc[0] == 0; xc.shift(), --e );
 
        if ( !xc[0] ) {
 
            // Zero.
            xc = [ e = 0 ];
 
            // Following IEEE 754 (2008) 6.3, n - n = -0 when rounding towards -Infinity.
            y['s'] = rm == 3 ? -1 : 1;
        }
 
        y['c'] = xc;
 
        // Get the number of digits of xc[0].
        for ( a = 1, b = xc[0]; b >= 10; b /= 10, a++ );
        y['e'] = a + e * LOGBASE - 1;
 
        return external ? rnd( y, pr, rm ) : y;
    };
 
 
    /*
     *   n % 0 =  N
     *   n % N =  N
     *   n % I =  n
     *   0 % n =  0
     *  -0 % n = -0
     *   0 % 0 =  N
     *   0 % N =  N
     *   0 % I =  0
     *   N % n =  N
     *   N % 0 =  N
     *   N % N =  N
     *   N % I =  N
     *   I % n =  N
     *   I % 0 =  N
     *   I % N =  N
     *   I % I =  N
     *
     * Return a new Decimal whose value is the value of this Decimal modulo Decimal(y, b), rounded
     * to precision significant digits using rounding mode rounding.
     *
     * The result depends on the modulo mode.
     *
     */
    P['modulo'] = P['mod'] = function ( y, b ) {
        var n, q,
            x = this,
            Decimal = x['constructor'],
            m = Decimal['modulo'];
 
        id = 9;
        y = new Decimal( y, b );
        b = y['s'];
        n = !x['c'] || !b || y['c'] && !y['c'][0];
 
        /*
         Return NaN if x is Infinity or NaN, or y is NaN or zero, else return x if y is Infinity
         or x is zero.
         */
        if ( n || !y['c'] || x['c'] && !x['c'][0] ) {
 
            return n
              ? new Decimal(NaN)
              : rnd( new Decimal(x), Decimal['precision'], Decimal['rounding'] );
        }
 
        external = false;
 
        if ( m == 9 ) {
 
            // Euclidian division: q = sign(y) * floor(x / abs(y))
            // r = x - qy    where  0 <= r < abs(y)
            y['s'] = 1;
            q = div( x, y, 0, 3, 1 );
            y['s'] = b;
            q['s'] *= b;
        } else {
            q = div( x, y, 0, m, 1 );
        }
 
        q = q['times'](y);
        external = true;
 
        return x['minus'](q);
    };
 
 
    /*
     * Return a new Decimal whose value is the natural logarithm of the value of this Decimal,
     * rounded to precision significant digits using rounding mode rounding.
     *
     */
    P['naturalLogarithm'] = P['ln'] = function () {
 
        return ln(this);
    };
 
 
    /*
     * Return a new Decimal whose value is the value of this Decimal negated, i.e. as if
     * multiplied by -1.
     *
     */
    P['negated'] = P['neg'] = function () {
        var x = new this['constructor'](this);
        x['s'] = -x['s'] || null;
 
        return rnd(x);
    };
 
 
    /*
     *  n + 0 = n
     *  n + N = N
     *  n + I = I
     *  0 + n = n
     *  0 + 0 = 0
     *  0 + N = N
     *  0 + I = I
     *  N + n = N
     *  N + 0 = N
     *  N + N = N
     *  N + I = N
     *  I + n = I
     *  I + 0 = I
     *  I + N = N
     *  I + I = I
     *
     * Return a new Decimal whose value is the value of this Decimal plus Decimal(y, b), rounded
     * to precision significant digits using rounding mode rounding.
     *
     */
    P['plus'] = function ( y, b ) {
        var t,
            x = this,
            Decimal = x['constructor'],
            a = x['s'];
 
        id = 10;
        y = new Decimal( y, b );
        b = y['s'];
 
        // Either NaN?
        if ( !a || !b ) {
 
            return new Decimal(NaN);
        }
 
        // Signs differ?
        if ( a != b ) {
            y['s'] = -b;
 
            return x['minus'](y);
        }
 
        var xc = x['c'],
            yc = y['c'],
            e = mathfloor( y['e'] / LOGBASE ),
            k = mathfloor( x['e'] / LOGBASE ),
            pr = Decimal['precision'],
            rm = Decimal['rounding'];
 
        if ( !k || !e ) {
 
            // Either Infinity?
            if ( !xc || !yc ) {
 
                // Return +-Infinity.
                return new Decimal( a / 0 );
            }
 
            // Either zero?
            if ( !xc[0] || !yc[0] ) {
 
                // Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
                x = yc[0] ? y : new Decimal( xc[0] ? x : a * 0 );
 
                return external ? rnd( x, pr, rm ) : x;
            }
        }
 
        xc = xc.slice();
 
        // Prepend zeros to equalise exponents. Note: Faster to use reverse then do unshifts.
        if ( a = k - e ) {
 
            if ( a < 0 ) {
                a = -a;
                t = xc;
                b = yc.length;
            } else {
                e = k;
                t = yc;
                b = xc.length;
            }
 
            if ( ( k = Math.ceil( pr / LOGBASE ) ) > b ) {
                b = k;
            }
 
            // Limit number of zeros prepended to max( pr, b ) + 1.
            if ( a > ++b ) {
                a = b;
                t.length = 1;
            }
 
            for ( t.reverse(); a--; t.push(0) );
            t.reverse();
        }
 
        // Point xc to the longer array.
        if ( xc.length - yc.length < 0 ) {
            t = yc, yc = xc, xc = t;
        }
 
        // Only start adding at yc.length - 1 as the further digits of xc can be left as they are.
        for ( a = yc.length, b = 0, k = BASE; a; xc[a] %= k ) {
            b = ( xc[--a] = xc[a] + yc[a] + b ) / k | 0;
        }
 
        if (b) {
            xc.unshift(b);
            ++e;
        }
 
        // Remove trailing zeros.
        for ( a = xc.length; xc[--a] == 0; xc.pop() );
 
        // No need to check for zero, as +x + +y != 0 && -x + -y != 0
 
        y['c'] = xc;
 
        // Get the number of digits of xc[0].
        for ( a = 1, b = xc[0]; b >= 10; b /= 10, a++ );
        y['e'] = a + e * LOGBASE - 1;
 
        return external ? rnd( y, pr, rm ) : y;
    };
 
 
    /*
     * Return the number of significant digits of this Decimal.
     *
     * z {boolean|number} Whether to count integer-part trailing zeros: true, false, 1 or 0.
     *
     */
    P['precision'] = P['sd'] = function (z) {
        var n = null,
            x = this;
 
        if ( z != n ) {
 
            Iif ( z !== !!z && z !== 1 && z !== 0 ) {
 
                // 'precision() argument not a boolean or binary digit: {z}'
                ifExceptionsThrow( x['constructor'], 'argument', z, 'precision', 1 );
            }
        }
 
        if ( x['c'] ) {
            n = getCoeffLength( x['c'] );
 
            if ( z && x['e'] + 1 > n ) {
                n = x['e'] + 1;
            }
        }
 
        return n;
    };
 
 
    /*
     * Return a new Decimal whose value is the value of this Decimal rounded to a whole number using
     * rounding mode rounding.
     *
     */
    P['round'] = function () {
        var x = this,
            Decimal = x['constructor'];
 
        return rnd( new Decimal(x), x['e'] + 1, Decimal['rounding'] );
    };
 
 
    /*
     *  sqrt(-n) =  N
     *  sqrt( N) =  N
     *  sqrt(-I) =  N
     *  sqrt( I) =  I
     *  sqrt( 0) =  0
     *  sqrt(-0) = -0
     *
     * Return a new Decimal whose value is the square root of this Decimal, rounded to precision
     * significant digits using rounding mode rounding.
     *
     */
    P['squareRoot'] = P['sqrt'] = function () {
        var m, n, sd, r, rep, t,
            x = this,
            c = x['c'],
            s = x['s'],
            e = x['e'],
            Decimal = x['constructor'],
            half = new Decimal(0.5);
 
        // Negative/NaN/Infinity/zero?
        if ( s !== 1 || !c || !c[0] ) {
 
            return new Decimal( !s || s < 0 && ( !c || c[0] ) ? NaN : c ? x : 1 / 0 );
        }
 
        external = false;
 
        // Initial estimate.
        s = Math.sqrt( +x );
 
        /*
         Math.sqrt underflow/overflow?
         Pass x to Math.sqrt as integer, then adjust the exponent of the result.
         */
        if ( s == 0 || s == 1 / 0 ) {
            n = coefficientToString(c);
 
            if ( ( n.length + e ) % 2 == 0 ) {
                n += '0';
            }
 
            s = Math.sqrt(n);
            e = mathfloor( ( e + 1 ) / 2 ) - ( e < 0 || e % 2 );
 
            Iif ( s == 1 / 0 ) {
                n = '1e' + e;
            } else {
                n = s.toExponential();
                n = n.slice( 0, n.indexOf('e') + 1 ) + e;
            }
 
            r = new Decimal(n);
        } else {
            r = new Decimal( s.toString() );
        }
 
        sd = ( e = Decimal['precision'] ) + 3;
 
        // Newton-Raphson iteration.
        for ( ; ; ) {
            t = r;
            r = half['times']( t['plus']( div( x, t, sd + 2, 1 ) ) );
 
            if ( coefficientToString( t['c'] ).slice( 0, sd ) ===
                ( n = coefficientToString( r['c'] ) ).slice( 0, sd ) ) {
                n = n.slice( sd - 3, sd + 1 );
 
                /*
                 The 4th rounding digit may be in error by -1 so if the 4 rounding digits are
                 9999 or 4999 (i.e. approaching a rounding boundary) continue the iteration.
                 */
                if ( n == '9999' || !rep && n == '4999' ) {
 
                    /*
                     On the first iteration only, check to see if rounding up gives the exact result
                     as the nines may infinitely repeat.
                     */
                    if ( !rep ) {
                        rnd( t, e + 1, 0 );
 
                        if ( t['times'](t)['eq'](x) ) {
                            r = t;
 
                            break;
                        }
                    }
                    sd += 4;
                    rep = 1;
                } else {
 
                    /*
                     If the rounding digits are null, 0{0,4} or 50{0,3}, check for an exact result.
                     If not, then there are further digits and m will be truthy.
                     */
                    if ( !+n || !+n.slice(1) && n.charAt(0) == '5' ) {
 
                        // Truncate to the first rounding digit.
                        rnd( r, e + 1, 1 );
                        m = !r['times'](r)['eq'](x);
                    }
 
                    break;
                }
            }
        }
        external = true;
 
        return rnd( r, e, Decimal['rounding'], m );
    };
 
 
    /*
     *  n * 0 = 0
     *  n * N = N
     *  n * I = I
     *  0 * n = 0
     *  0 * 0 = 0
     *  0 * N = N
     *  0 * I = N
     *  N * n = N
     *  N * 0 = N
     *  N * N = N
     *  N * I = N
     *  I * n = I
     *  I * 0 = N
     *  I * N = N
     *  I * I = I
     *
     * Return a new Decimal whose value is this Decimal times Decimal(y), rounded to precision
     * significant digits using rounding mode rounding.
     *
     */
    P['times'] = function ( y, b ) {
        var c, e,
            x = this,
            Decimal = x['constructor'],
            xc = x['c'],
            yc = ( id = 11, y = new Decimal( y, b ), y['c'] ),
            i = mathfloor( x['e'] / LOGBASE ),
            j = mathfloor( y['e'] / LOGBASE ),
            a = x['s'];
 
        b = y['s'];
 
        y['s'] = a == b ? 1 : -1;
 
        // Either NaN/Infinity/0?
        if ( !i && ( !xc || !xc[0] ) || !j && ( !yc || !yc[0] ) ) {
 
            // Either NaN?
            return new Decimal( !a || !b ||
 
              // x is 0 and y is Infinity  or y is 0 and x is Infinity?
              xc && !xc[0] && !yc || yc && !yc[0] && !xc
 
                // Return NaN.
                ? NaN
 
                // Either Infinity?
                : !xc || !yc
 
                  // Return +-Infinity.
                  ? y['s'] / 0
 
                  // x or y is 0. Return +-0.
                  : y['s'] * 0 );
        }
 
        e = i + j;
        a = xc.length;
        b = yc.length;
 
        if ( a < b ) {
 
            // Swap.
            c = xc, xc = yc, yc = c;
            j = a, a = b, b = j;
        }
 
        for ( j = a + b, c = []; j--; c.push(0) );
 
        // Multiply!
        for ( i = b - 1; i > -1; i-- ) {
            b = 0;
 
            for ( j = a + i; j > i; ) {
                  b = c[j] + yc[i] * xc[j - i - 1] + b;
                  c[j--] = b % BASE | 0;
                  b = b / BASE | 0;
            }
            c[j] = ( c[j] + b ) % BASE | 0;
        }
 
        if (b) {
            ++e;
        } else Eif ( !c[0] ) {
 
            // Remove leading zero.
            c.shift();
        }
 
        // Remove trailing zeros.
        for ( j = c.length; !c[--j]; c.pop() );
        y['c'] = c;
 
        // Get the number of digits of c[0].
        for ( a = 1, b = c[0]; b >= 10; b /= 10, a++ );
        y['e'] = a + e * LOGBASE - 1;
 
        return external ? rnd( y, Decimal['precision'], Decimal['rounding'] ) : y;
    };
 
 
    /*
     * Return a new Decimal whose value is the value of this Decimal rounded to a maximum of dp
     * decimal places using rounding mode rm or rounding if rm is omitted.
     *
     * If dp is omitted, return a new Decimal whose value is the value of this Decimal.
     *
     * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive.
     * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
     *
     * 'toDP() dp out of range: {dp}'
     * 'toDP() dp not an integer: {dp}'
     * 'toDP() rounding mode not an integer: {rm}'
     * 'toDP() rounding mode out of range: {rm}'
     *
     */
    P['toDecimalPlaces'] = P['toDP'] = function ( dp, rm ) {
        var x = this;
        x = new x['constructor'](x);
 
        return dp == null || !checkArg( x, dp, 'toDP' )
          ? x
          : rnd( x, ( dp | 0 ) + x['e'] + 1, checkRM( x, rm, 'toDP' ) );
    };
 
 
    /*
     * Return a string representing the value of this Decimal in exponential notation rounded to dp
     * fixed decimal places using rounding mode rounding.
     *
     * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive.
     * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
     *
     * errors true: Throw if dp and rm are not undefined, null or integers in range.
     * errors false: Ignore dp and rm if not numbers or not in range, and truncate non-integers.
     *
     * 'toExponential() dp not an integer: {dp}'
     * 'toExponential() dp out of range: {dp}'
     * 'toExponential() rounding mode not an integer: {rm}'
     * 'toExponential() rounding mode out of range: {rm}'
     *
     */
    P['toExponential'] = function ( dp, rm ) {
        var x = this;
 
        return x['c']
          ? format( x, dp != null && checkArg( x, dp, 'toExponential' ) ? dp | 0 : null,
            dp != null && checkRM( x, rm, 'toExponential' ), 1 )
          : x.toString();
    };
 
 
    /*
     * Return a string representing the value of this Decimal in normal (fixed-point) notation to
     * dp fixed decimal places and rounded using rounding mode rm or rounding if rm is omitted.
     *
     * Note: as with JS numbers, (-0).toFixed(0) is '0', but e.g. (-0.00001).toFixed(0) is '-0'.
     *
     * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive.
     * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
     *
     * errors true: Throw if dp and rm are not undefined, null or integers in range.
     * errors false: Ignore dp and rm if not numbers or not in range, and truncate non-integers.
     *
     * 'toFixed() dp not an integer: {dp}'
     * 'toFixed() dp out of range: {dp}'
     * 'toFixed() rounding mode not an integer: {rm}'
     * 'toFixed() rounding mode out of range: {rm}'
     *
     */
    P['toFixed'] = function ( dp, rm ) {
        var str,
            x = this,
            Decimal = x['constructor'],
            neg = Decimal['toExpNeg'],
            pos = Decimal['toExpPos'];
 
        if ( dp != null ) {
            dp = checkArg( x, dp, str = 'toFixed' ) ? x['e'] + ( dp | 0 ) : null;
            rm = checkRM( x, rm, str );
        }
 
        // Prevent toString returning exponential notation;
        Decimal['toExpNeg'] = -( Decimal['toExpPos'] = 1 / 0 );
 
        if ( dp == null || !x['c'] ) {
            str = x.toString();
        } else {
            str = format( x, dp, rm );
 
            // (-0).toFixed() is '0', but (-0.1).toFixed() is '-0'.
            // (-0).toFixed(1) is '0.0', but (-0.01).toFixed(1) is '-0.0'.
            if ( x['s'] < 0 && x['c'] ) {
 
                // As e.g. (-0).toFixed(3), will wrongly be returned as -0.000 from toString.
                if ( !x['c'][0] ) {
                    str = str.replace( '-', '' );
 
                // As e.g. -0.5 if rounded to -0 will cause toString to omit the minus sign.
                } else if ( str.indexOf('-') < 0 ) {
                    str = '-' + str;
                }
            }
        }
        Decimal['toExpNeg'] = neg;
        Decimal['toExpPos'] = pos;
 
        return str;
    };
 
 
    /*
     * Return a string representing the value of this Decimal in fixed-point notation to dp decimal
     * places, rounded using rounding mode rm or Decimal.rounding if rm is omitted, and formatted
     * according to the following properties of the Decimal.format object.
     *
     *  Decimal.format = {
     *      decimalSeparator : '.',
     *      groupSeparator : ',',
     *      groupSize : 3,
     *      secondaryGroupSize : 0,
     *      fractionGroupSeparator : '\xA0',    // non-breaking space
     *      fractionGroupSize : 0
     *  };
     *
     * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive.
     * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive
     *
     * (If dp or rm are invalid the error message will give the offending method call as toFixed.)
     *
     */
    P['toFormat'] = function( dp, rm ) {
        var x = this;
 
        if ( !x['c'] ) {
            return x.toString();
        }
 
        var i,
            isNeg = x['s'] < 0,
            f = x['constructor']['format'],
            groupSeparator = f['groupSeparator'],
            g1 = +f['groupSize'],
            g2 = +f['secondaryGroupSize'],
            arr = x.toFixed( dp, rm ).split('.'),
            intPart = arr[0],
            fractionPart = arr[1],
            intDigits = isNeg ? intPart.slice(1) : intPart,
            len = intDigits.length;
 
        if (g2) {
            len -= ( i = g1, g1 = g2, g2 = i );
        }
 
        if ( g1 > 0 && len > 0 ) {
            i = len % g1 || g1;
            intPart = intDigits.substr( 0, i );
 
            for ( ; i < len; i += g1 ) {
                intPart += groupSeparator + intDigits.substr( i, g1 );
            }
 
            if ( g2 > 0 ) {
                intPart += groupSeparator + intDigits.slice(i);
            }
 
            if (isNeg) {
                intPart = '-' + intPart;
            }
        }
 
        return fractionPart
          ? intPart + f['decimalSeparator'] + ( ( g2 = +f['fractionGroupSize'] )
            ? fractionPart.replace( new RegExp( '\\d{' + g2 + '}\\B', 'g' ),
              '$&' + f['fractionGroupSeparator'] )
            : fractionPart )
          : intPart;
    };
 
 
    /*
     * Return a string array representing the value of this Decimal as a simple fraction with an
     * integer numerator and an integer denominator.
     *
     * The denominator will be a positive non-zero value less than or equal to the specified
     * maximum denominator. If a maximum denominator is not specified, the denominator will be
     * the lowest value necessary to represent the number exactly.
     *
     * [maxD] {number|string|Decimal} Maximum denominator. Integer >= 1 and < Infinity.
     *
     */
    P['toFraction'] = function (maxD) {
        var d0, d2, e, frac, n, n0, p, q,
            x = this,
            Decimal = x['constructor'],
            n1 = d0 = new Decimal( Decimal['ONE'] ),
            d1 = n0 = new Decimal(0),
            xc = x['c'],
            d = new Decimal(d1);
 
        // NaN, Infinity.
        Iif ( !xc ) {
 
            return x.toString();
        }
 
        e = d['e'] = getCoeffLength(xc) - x['e'] - 1;
        d['c'][0] = mathpow( 10, ( p = e % LOGBASE ) < 0 ? LOGBASE + p : p );
 
        // If maxD is undefined or null...
        if ( maxD == null ||
 
             // or NaN...
             ( !( id = 12, n = new Decimal(maxD) )['s'] ||
 
               // or less than 1, or Infinity...
               ( outOfRange = n['cmp'](n1) < 0 || !n['c'] ) ||
 
                 // or not an integer...
                 ( Decimal['errors'] && mathfloor( n['e'] / LOGBASE ) < n['c'].length - 1 ) ) &&
 
                   // 'toFraction() max denominator not an integer: {maxD}'
                   // 'toFraction() max denominator out of range: {maxD}'
                   !ifExceptionsThrow( Decimal, 'max denominator', maxD, 'toFraction', 0 ) ||
 
                     // or greater than the maximum denominator needed to specify the value exactly.
                     ( maxD = n )['cmp'](d) > 0 ) {
 
            // d is 10**e, n1 is 1.
            maxD = e > 0 ? d : n1;
        }
 
        external = false;
        n = new Decimal( coefficientToString(xc) );
        p = Decimal['precision'];
        Decimal['precision'] = e = xc.length * LOGBASE * 2;
 
        for ( ; ; )  {
            q = div( n, d, 0, 1, 1 );
            d2 = d0['plus']( q['times'](d1) );
 
            if ( d2['cmp'](maxD) == 1 ) {
 
                break;
            }
            d0 = d1;
            d1 = d2;
 
            n1 = n0['plus']( q['times']( d2 = n1 ) );
            n0 = d2;
 
            d = n['minus']( q['times']( d2 = d ) );
            n = d2;
        }
 
        d2 = div( maxD['minus'](d0), d1, 0, 1, 1 );
        n0 = n0['plus']( d2['times'](n1) );
        d0 = d0['plus']( d2['times'](d1) );
        n0['s'] = n1['s'] = x['s'];
 
        // Determine which fraction is closer to x, n0/d0 or n1/d1?
        frac = div( n1, d1, e, 1 )['minus'](x)['abs']()['cmp'](
               div( n0, d0, e, 1 )['minus'](x)['abs']() ) < 1
          ? [ n1 + '', d1 + '' ]
          : [ n0 + '', d0 + '' ];
 
        external = true;
        Decimal['precision'] = p;
 
        return frac;
    };
 
 
    /*
     * Returns a new Decimal whose value is the nearest multiple of the magnitude of n to the value
     * of this Decimal.
     *
     * If the value of this Decimal is equidistant from two multiples of n, the rounding mode rm,
     * or rounding if rm is omitted or is null or undefined, determines the direction of the
     * nearest multiple.
     *
     * In the context of this method, rounding mode 4 (ROUND_HALF_UP) is the same as rounding mode 0
     * (ROUND_UP), and so on.
     *
     * The return value will always have the same sign as this Decimal, unless either this Decimal
     * or n is NaN, in which case the return value will be also be NaN.
     *
     * The return value is not rounded to precision significant digits.
     *
     * n {number|string|Decimal} The magnitude to round to a multiple of.
     * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
     *
     * 'toNearest() rounding mode not an integer: {rm}'
     * 'toNearest() rounding mode out of range: {rm}'
     *
     */
    P['toNearest'] = function ( n, rm ) {
        var x = this,
            Decimal = x['constructor'];
 
        x = new Decimal(x);
 
        if ( n == null ) {
            n = new Decimal( Decimal['ONE'] );
            rm = Decimal['rounding'];
        } else {
            id = 17;
            n = new Decimal(n);
            rm = checkRM( x, rm, 'toNearest' );
        }
 
        // If n is finite...
        if ( n['c'] ) {
 
           // If x is finite...
            if ( x['c'] ) {
 
                if ( n['c'][0] ) {
                    external = false;
                    x = div( x, n, 0, rm < 4 ? [4, 5, 7, 8][rm] : rm, 1 )['times'](n);
                    external = true;
                    rnd(x);
                } else {
                    x['c'] = [ x['e'] = 0 ];
                }
            }
 
        // n is NaN or +-Infinity. If x is not NaN...
        } else if ( x['s'] ) {
 
            // If n is +-Infinity...
            if ( n['s'] ) {
                n['s'] = x['s'];
            }
            x = n;
        }
 
        return x;
    };
 
 
    /*
     * Return the value of this Decimal converted to a number primitive.
     *
     */
    P['toNumber'] = function () {
        var x = this;
 
        // Ensure zero has correct sign.
        return +x || ( x['s'] ? 0 * x['s'] : NaN );
    };
 
 
    /*
     * Return a new Decimal whose value is the value of this Decimal raised to the power
     * Decimal(y, b), rounded to precision significant digits using rounding mode rounding.
     *
     * ECMAScript compliant.
     *
     *   x is any value, including NaN.
     *   n is any number, including �Infinity unless stated.
     *
     *   pow( x, NaN )                           = NaN
     *   pow( x, �0 )                            = 1
 
     *   pow( NaN, nonzero )                     = NaN
     *   pow( abs(n) > 1, +Infinity )            = +Infinity
     *   pow( abs(n) > 1, -Infinity )            = +0
     *   pow( abs(n) == 1, �Infinity )           = NaN
     *   pow( abs(n) < 1, +Infinity )            = +0
     *   pow( abs(n) < 1, -Infinity )            = +Infinity
     *   pow( +Infinity, n > 0 )                 = +Infinity
     *   pow( +Infinity, n < 0 )                 = +0
     *   pow( -Infinity, odd integer > 0 )       = -Infinity
     *   pow( -Infinity, even integer > 0 )      = +Infinity
     *   pow( -Infinity, odd integer < 0 )       = -0
     *   pow( -Infinity, even integer < 0 )      = +0
     *   pow( +0, n > 0 )                        = +0
     *   pow( +0, n < 0 )                        = +Infinity
     *   pow( -0, odd integer > 0 )              = -0
     *   pow( -0, even integer > 0 )             = +0
     *   pow( -0, odd integer < 0 )              = -Infinity
     *   pow( -0, even integer < 0 )             = +Infinity
     *   pow( finite n < 0, finite non-integer ) = NaN
     *
     * For non-integer and larger exponents pow(x, y) is calculated using
     *
     *   x^y = exp(y*ln(x))
     *
     * Assuming the first 15 rounding digits are each equally likely to be any digit 0-9, the
     * probability of an incorrectly rounded result
     * P( [49]9{14} | [50]0{14} ) = 2 * 0.2 * 10^-14 = 4e-15 = 1/2.5e+14
     * i.e. 1 in 250,000,000,000,000
     *
     * If a result is incorrectly rounded the maximum error will be 1 ulp (unit in last place).
     *
     * y {number|string|Decimal} The power to which to raise this Decimal.
     * [b] {number} The base of y.
     *
     */
    P['toPower'] = P['pow'] = function ( y, b ) {
        var a, e, n, r,
            x = this,
            Decimal = x['constructor'],
            s = x['s'],
            yN = +( id = 13, y = new Decimal( y, b ) ),
            i = yN < 0 ? -yN : yN,
            pr = Decimal['precision'],
            rm = Decimal['rounding'];
 
        // Handle +-Infinity, NaN and +-0.
        if ( !x['c'] || !y['c'] || ( n = !x['c'][0] ) || !y['c'][0] ) {
 
            // valueOf -0 is 0, so check for 0 then multiply it by the sign.
            return new Decimal( mathpow( n ? s * 0 : +x, yN ) );
        }
 
        x = new Decimal(x);
        a = x['c'].length;
 
        // if x == 1
        if ( !x['e'] && x['c'][0] == x['s'] && a == 1 ) {
 
            return x;
        }
 
        b = y['c'].length - 1;
 
        // if y == 1
        if ( !y['e'] && y['c'][0] == y['s'] && !b ) {
            r = rnd( x, pr, rm );
        } else {
            e = mathfloor( y['e'] / LOGBASE );
            n = e >= b;
 
            // If y is not an integer and x is negative, return NaN.
            if ( !n && s < 0 ) {
                r = new Decimal(NaN);
            } else {
 
                /*
                 If the approximate number of significant digits of x multiplied by abs(y) is less
                 than INT_POW_LIMIT use the 'exponentiation by squaring' algorithm.
                 */
                if ( n && a * LOGBASE * i < INT_POW_LIMIT ) {
                    r = intPow( Decimal, x, i );
 
                    if ( y['s'] < 0 ) {
 
                        return Decimal['ONE']['div'](r);
                    }
                } else {
 
                    // Result is negative if x is negative and the last digit of integer y is odd.
                    s = s < 0 && y['c'][ Math.max( e, b ) ] & 1 ? -1 : 1;
 
                    b = mathpow( +x, yN );
 
                    /*
                     Estimate result exponent.
                     x^y = 10^e,  where e = y * log10(x)
                     log10(x) = log10(x_significand) + x_exponent
                     log10(x_significand) = ln(x_significand) / ln(10)
                     */
                    e = b == 0 || !isFinite(b)
                      ? mathfloor( yN * ( Math.log( '0.' + coefficientToString( x['c'] ) ) /
                        Math.LN10 + x['e'] + 1 ) )
                      : new Decimal( b + '' )['e'];
 
                    // Estimate may be incorrect e.g. x: 0.999999999999999999, y: 2.29, e: 0, r.e:-1
 
                    // Overflow/underflow?
                    if ( e > Decimal['maxE'] + 1 || e < Decimal['minE'] - 1 ) {
 
                        return new Decimal( e > 0 ? s / 0 : 0 );
                    }
 
                    external = false;
                    Decimal['rounding'] = x['s'] = 1;
 
                    /*
                     Estimate extra digits needed from ln(x) to ensure five correct rounding digits
                     in result (i was unnecessary before max exponent was extended?).
                     Example of failure before i was introduced: (precision: 10),
                     new Decimal(2.32456).pow('2087987436534566.46411')
                     should be 1.162377823e+764914905173815, but is 1.162355823e+764914905173815
                     */
                    i = Math.min( 12, ( e + '' ).length );
 
                    // r = x^y = exp(y*ln(x))
                    r = exp( y['times']( ln( x, pr + i ) ), pr );
 
                    // Truncate to the required precision plus five rounding digits.
                    r = rnd( r, pr + 5, 1 );
 
                    /*
                     If the rounding digits are [49]9999 or [50]0000 increase the precision by 10
                     and recalculate the result.
                     */
                    if ( checkRoundingDigits( r['c'], pr, rm ) ) {
                        e = pr + 10;
 
                        // Truncate to the increased precision plus five rounding digits.
                        r = rnd( exp( y['times']( ln( x, e + i ) ), e ), e + 5, 1 );
 
                        /*
                          Check for 14 nines from the 2nd rounding digit (the first rounding digit
                          may be 4 or 9).
                         */
                        if ( +coefficientToString( r['c'] ).slice( pr + 1, pr + 15 ) + 1 == 1e14 ) {
                            r = rnd( r, pr + 1, 0 );
                        }
                    }
 
                    r['s'] = s;
                    external = true;
                    Decimal['rounding'] = rm;
                }
 
                r = rnd( r, pr, rm );
            }
        }
 
        return r;
    };
 
 
    /*
     * Return a string representing the value of this Decimal rounded to sd significant digits
     * using rounding mode rounding.
     *
     * Return exponential notation if sd is less than the number of digits necessary to represent
     * the integer part of the value in normal notation.
     *
     * sd {number} Significant digits. Integer, 1 to MAX_DIGITS inclusive.
     * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
     *
     * errors true: Throw if sd and rm are not undefined, null or integers in range.
     * errors false: Ignore sd and rm if not numbers or not in range, and truncate non-integers.
     *
     * 'toPrecision() sd not an integer: {sd}'
     * 'toPrecision() sd out of range: {sd}'
     * 'toPrecision() rounding mode not an integer: {rm}'
     * 'toPrecision() rounding mode out of range: {rm}'
     *
     */
    P['toPrecision'] = function ( sd, rm ) {
        var x = this;
 
        return sd != null && checkArg( x, sd, 'toPrecision', 1 ) && x['c']
          ? format( x, --sd | 0, checkRM( x, rm, 'toPrecision' ), 2 )
          : x.toString();
    };
 
 
    /*
     * Return a new Decimal whose value is this Decimal rounded to a maximum of d significant
     * digits using rounding mode rm, or to precision and rounding respectively if omitted.
     *
     * [d] {number} Significant digits. Integer, 1 to MAX_DIGITS inclusive.
     * [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
     *
     * 'toSD() digits out of range: {d}'
     * 'toSD() digits not an integer: {d}'
     * 'toSD() rounding mode not an integer: {rm}'
     * 'toSD() rounding mode out of range: {rm}'
     *
     */
    P['toSignificantDigits'] = P['toSD'] = function ( d, rm ) {
        var x = this,
            Decimal = x['constructor'];
 
        x = new Decimal(x);
 
        return d == null || !checkArg( x, d, 'toSD', 1 )
          ? rnd( x, Decimal['precision'], Decimal['rounding'] )
          : rnd( x, d | 0, checkRM( x, rm, 'toSD' ) );
    };
 
 
    /*
     * Return a string representing the value of this Decimal in base b, or base 10 if b is
     * omitted. If a base is specified, including base 10, round to precision significant digits
     * using rounding mode rounding.
     *
     * Return exponential notation if a base is not specified, and this Decimal has a positive
     * exponent equal to or greater than toExpPos, or a negative exponent equal to or less than
     * toExpNeg.
     *
     * [b] {number} Base. Integer, 2 to 64 inclusive.
     *
     */
     P['toString'] = function (b) {
        var u, str, strL,
            x = this,
            Decimal = x['constructor'],
            xe = x['e'];
 
        // Infinity or NaN?
        if ( xe === null ) {
            str = x['s'] ? 'Infinity' : 'NaN';
 
        // Exponential format?
        } else if ( b === u && ( xe <= Decimal['toExpNeg'] || xe >= Decimal['toExpPos'] ) ) {
 
            return format( x, null, Decimal['rounding'], 1 );
        } else {
            str = coefficientToString( x['c'] );
 
            // Negative exponent?
            if ( xe < 0 ) {
 
                // Prepend zeros.
                for ( ; ++xe; str = '0' + str );
                str = '0.' + str;
 
            // Positive exponent?
            } else if ( strL = str.length, xe > 0 ) {
 
                if ( ++xe > strL ) {
 
                    // Append zeros.
                    for ( xe -= strL; xe-- ; str += '0' );
 
                } else if ( xe < strL ) {
                    str = str.slice( 0, xe ) + '.' + str.slice(xe);
                }
 
            // Exponent zero.
            } else {
                u = str.charAt(0);
 
                if ( strL > 1 ) {
                    str = u + '.' + str.slice(1);
 
                // Avoid '-0'
                } else if ( u == '0' ) {
 
                    return u;
                }
            }
 
            if ( b != null ) {
 
                if ( !( outOfRange = !( b >= 2 && b < 65 ) ) &&
                  ( b == (b | 0) || !Decimal['errors'] ) ) {
                    str = convertBase( Decimal, str, b | 0, 10, x['s'] );
 
                    // Avoid '-0'
                    Iif ( str == '0' ) {
 
                        return str;
                    }
                } else {
 
                    // 'toString() base not an integer: {b}'
                    // 'toString() base out of range: {b}'
                    ifExceptionsThrow( Decimal, 'base', b, 'toString', 0 );
                }
            }
        }
 
        return x['s'] < 0 ? '-' + str : str;
    };
 
 
    /*
     * Return a new Decimal whose value is the value of this Decimal truncated to a whole number.
     *
     */
    P['truncated'] = P['trunc'] = function () {
 
        return rnd( new this['constructor'](this), this['e'] + 1, 1 );
    };
 
 
    /*
     * Return as toString, but do not accept a base argument.
     *
     * Ensures that JSON.stringify() uses toString for serialization.
     *
     */
    P['valueOf'] = P['toJSON'] = function () {
 
        return this.toString();
    };
 
 
    /*
    // Add aliases to match BigDecimal method names.
    P['add'] = P['plus'];
    P['subtract'] = P['minus'];
    P['multiply'] = P['times'];
    P['divide'] = P['div'];
    P['remainder'] = P['mod'];
    P['compareTo'] = P['cmp'];
    P['negate'] = P['neg'];
     */
 
 
    // Private functions for Decimal.prototype methods.
 
 
    /*
     *  coefficientToString
     *  checkRoundingDigits
     *  checkRM
     *  checkArg
     *  convertBase
     *  div
     *  exp
     *  format
     *  getCoeffLength
     *  ifExceptionsThrow
     *  intPow
     *  ln
     *  rnd
     */
 
 
    function coefficientToString(a) {
        var s, z,
            i = 1,
            j = a.length,
            r = a[0] + '';
 
        for ( ; i < j; i++ ) {
            s = a[i] + '';
 
            for ( z = LOGBASE - s.length; z--; ) {
                s = '0' + s;
            }
 
            r += s;
        }
 
        // '0'
        for ( j = r.length; r.charCodeAt(--j) === 48; );
 
        return r.slice( 0, j + 1 || 1 );
    }
 
 
    /*
     * Check 5 rounding digits if repeating is null, 4 otherwise.
     * repeating == null if caller is log or pow,
     * repeating != null if caller is ln or exp.
     *
     *
     // Previous, much simpler implementation when coefficient was base 10.
     function checkRoundingDigits( c, i, rm, repeating ) {
         return ( !repeating && rm > 3 && c[i] == 4 ||
           ( repeating || rm < 4 ) && c[i] == 9 ) && c[i + 1] == 9 && c[i + 2] == 9 &&
             c[i + 3] == 9 && ( repeating != null || c[i + 4] == 9 ) ||
               repeating == null && ( c[i] == 5 || !c[i] ) && !c[i + 1] && !c[i + 2] &&
                 !c[i + 3] && !c[i + 4];
     }
     */
    function checkRoundingDigits( c, i, rm, repeating ) {
        var ci, k, n, r, rd;
 
        // Get the length of the first element of the array c.
        for ( k = 1, n = c[0]; n >= 10; n /= 10, k++ );
 
        n = i - k;
 
        // Is the rounding digit in the first element of c?
        if ( n < 0 ) {
            n += LOGBASE;
            ci = 0;
        } else {
            ci = Math.ceil( ( n + 1 ) / LOGBASE );
            n %= LOGBASE;
        }
 
        k = mathpow( 10, LOGBASE - n );
        rd = c[ci] % k | 0;
 
        if ( repeating == null ) {
 
            if ( n < 3 ) {
 
                if ( n == 0 ) {
                    rd = rd / 100 | 0;
                } else if ( n == 1 ) {
                    rd = rd / 10 | 0;
                }
 
                r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 50000 || rd == 0;
            } else {
                r = ( rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2 ) &&
                    ( c[ci + 1] / k / 100 | 0 ) == mathpow( 10, n - 2 ) - 1 ||
                        ( rd == k / 2 || rd == 0 ) && ( c[ci + 1] / k / 100 | 0 ) == 0;
            }
        } else {
 
            if ( n < 4 ) {
 
                if ( n == 0 ) {
                    rd = rd / 1000 | 0;
                } else if ( n == 1 ) {
                    rd = rd / 100 | 0;
                } else if ( n == 2 ) {
                    rd = rd / 10 | 0;
                }
 
                r = ( repeating || rm < 4 ) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
            } else {
                r = ( ( repeating || rm < 4 ) && rd + 1 == k ||
                ( !repeating && rm > 3 ) && rd + 1 == k / 2 ) &&
                    ( c[ci + 1] / k / 1000 | 0 ) == mathpow( 10, n - 3 ) - 1;
            }
        }
 
        return r;
    }
 
 
    /*
     * Check and return rounding mode. If rm is invalid, return rounding mode rounding.
     */
    function checkRM( x, rm, method ) {
        var Decimal = x['constructor'];
 
        return rm == null || ( ( outOfRange = rm < 0 || rm > 8 ) ||
          rm !== 0 && ( Decimal['errors'] ? parseInt : parseFloat )(rm) != rm ) &&
            !ifExceptionsThrow( Decimal, 'rounding mode', rm, method, 0 )
              ? Decimal['rounding'] : rm | 0;
    }
 
 
    /*
     * Check that argument n is in range, return true or false.
     */
    function checkArg( x, n, method, min ) {
        var Decimal = x['constructor'];
 
        return !( outOfRange = n < ( min || 0 ) || n >= MAX_DIGITS + 1 ) &&
 
          /*
           * Include 'n === 0' because Opera has 'parseFloat(-0) == -0' as false
           * despite having 'parseFloat(-0) === -0 && parseFloat('-0') === -0 && 0 == -0' as true.
           */
          ( n === 0 || ( Decimal['errors'] ? parseInt : parseFloat )(n) == n ) ||
            ifExceptionsThrow( Decimal, 'argument', n, method, 0 );
    }
 
 
    /*
     * Convert a numeric string of baseIn to a numeric string of baseOut.
     */
    convertBase = (function () {
 
        /*
         * Convert string of baseIn to an array of numbers of baseOut.
         * Eg. convertBase('255', 10, 16) returns [15, 15].
         * Eg. convertBase('ff', 16, 10) returns [2, 5, 5].
         */
        function toBaseOut( str, baseIn, baseOut ) {
            var j,
                arr = [0],
                arrL,
                i = 0,
                strL = str.length;
 
            for ( ; i < strL; ) {
                for ( arrL = arr.length; arrL--; arr[arrL] *= baseIn );
                arr[ j = 0 ] += NUMERALS.indexOf( str.charAt( i++ ) );
 
                for ( ; j < arr.length; j++ ) {
 
                    if ( arr[j] > baseOut - 1 ) {
 
                        if ( arr[j + 1] == null ) {
                            arr[j + 1] = 0;
                        }
                        arr[j + 1] += arr[j] / baseOut | 0;
                        arr[j] %= baseOut;
                    }
                }
            }
 
            return arr.reverse();
        }
 
        return function ( Decimal, str, baseOut, baseIn, sign ) {
            var e, j, r, x, xc, y,
                i = str.indexOf( '.' ),
                pr = Decimal['precision'],
                rm = Decimal['rounding'];
 
            Eif ( baseIn < 37 ) {
                str = str.toLowerCase();
            }
 
            // Non-integer.
            if ( i >= 0 ) {
                str = str.replace( '.', '' );
                y = new Decimal(baseIn);
                x = intPow( Decimal, y, str.length - i );
 
                /*
                 Convert str as if an integer, then divide the result by its base raised to a power
                 such that the fraction part will be restored.
                 Use toFixed to avoid possible exponential notation.
                 */
                y['c'] = toBaseOut( x.toFixed(), 10, baseOut );
                y['e'] = y['c'].length;
            }
 
            // Convert the number as integer.
            xc = toBaseOut( str, baseIn, baseOut );
            e = j = xc.length;
 
            // Remove trailing zeros.
            for ( ; xc[--j] == 0; xc.pop() );
 
            if ( !xc[0] ) {
 
                return '0';
            }
 
            if ( i < 0 ) {
                e--;
            } else {
                x['c'] = xc;
                x['e'] = e;
 
                // sign is needed for correct rounding.
                x['s'] = sign;
                x = div( x, y, pr, rm, 0, baseOut );
                xc = x['c'];
                r = x['r'];
                e = x['e'];
            }
 
            // The rounding digit, i.e. the digit after the digit that may be rounded up.
            i = xc[pr];
            j = baseOut / 2;
            r = r || xc[pr + 1] != null;
 
            if ( rm < 4
              ? ( i != null || r ) && ( rm == 0 || rm == ( x['s'] < 0 ? 3 : 2 ) )
              : i > j || i == j && ( rm == 4 || r || rm == 6 && xc[pr - 1] & 1 ||
                rm == ( x['s'] < 0 ? 8 : 7 ) ) ) {
 
                xc.length = pr;
 
                // Rounding up may mean the previous digit has to be rounded up and so on.
                for ( --baseOut; ++xc[--pr] > baseOut; ) {
                    xc[pr] = 0;
 
                    if ( !pr ) {
                        ++e;
                        xc.unshift(1);
                    }
                }
            } else {
                xc.length = pr;
            }
 
            // Determine trailing zeros.
            for ( j = xc.length; !xc[--j]; );
 
            // E.g. [4, 11, 15] becomes 4bf.
            for ( i = 0, str = ''; i <= j; str += NUMERALS.charAt( xc[i++] ) );
 
            // Negative exponent?
            if ( e < 0 ) {
 
                // Prepend zeros.
                for ( ; ++e; str = '0' + str );
 
                str = '0.' + str;
 
            // Positive exponent?
            } else {
                i = str.length;
 
                if ( ++e > i ) {
 
                    // Append zeros.
                    for ( e -= i; e-- ; str += '0' );
 
                } else if ( e < i ) {
                    str = str.slice( 0, e ) + '.' + str.slice(e);
                }
            }
 
            // No negative numbers: the caller will add the sign.
            return str;
        };
    })();
 
 
    /*
     * Perform division in the specified base. Called by div and convertBase.
     */
    var div = ( function () {
 
        // Assumes non-zero x and k, and hence non-zero result.
        function multiplyInteger( x, k, base ) {
            var temp,
                carry = 0,
                i = x.length;
 
            for ( x = x.slice(); i--; ) {
                temp = x[i] * k + carry;
                x[i] = temp % base | 0;
                carry = temp / base | 0;
            }
 
            if (carry) {
                x.unshift(carry);
            }
 
            return x;
        }
 
        function compare( a, b, aL, bL ) {
            var i, cmp;
 
            if ( aL != bL ) {
                cmp = aL > bL ? 1 : -1;
            } else {
 
                for ( i = cmp = 0; i < aL; i++ ) {
 
                    if ( a[i] != b[i] ) {
                        cmp = a[i] > b[i] ? 1 : -1;
 
                        break;
                    }
                }
            }
 
            return cmp;
        }
 
        function subtract( a, b, aL, base ) {
            var i = 0;
 
            // Subtract b from a.
            for ( ; aL--; ) {
                a[aL] -= i;
                i = a[aL] < b[aL] ? 1 : 0;
                a[aL] = i * base + a[aL] - b[aL];
            }
 
            // Remove leading zeros.
            for ( ; !a[0] && a.length > 1; a.shift() );
        }
 
        // x: dividend, y: divisor.
        return function ( x, y, pr, rm, dp, base ) {
            var cmp, e, i, logbase, more, n, prod, prodL, q, qc, rem, remL, rem0, t, xi, xL, yc0,
                yL, yz,
                Decimal = x['constructor'],
                s = x['s'] == y['s'] ? 1 : -1,
                xc = x['c'],
                yc = y['c'];
 
            // Either NaN, Infinity or 0?
            if ( !xc || !xc[0] || !yc || !yc[0] ) {
 
                return new Decimal(
 
                  // Return NaN if either NaN, or both Infinity or 0.
                  !x['s'] || !y['s'] || ( xc ? yc && xc[0] == yc[0] : !yc ) ? NaN :
 
                    // Return +-0 if x is 0 or y is +-Infinity, or return +-Infinity as y is 0.
                    xc && xc[0] == 0 || !yc ? s * 0 : s / 0
                );
            }
 
            if (base) {
                logbase = 1;
                e = x['e'] - y['e'];
            } else {
                base = BASE;
                logbase = LOGBASE;
                e = mathfloor( x['e'] / logbase ) - mathfloor( y['e'] / logbase );
            }
 
            yL = yc.length;
            xL = xc.length;
            q = new Decimal(s);
            qc = q['c'] = [];
 
            // Result exponent may be one less then the current value of e.
            // The coefficients of the Decimals from convertBase may have trailing zeros.
            for ( i = 0; yc[i] == ( xc[i] || 0 ); i++ );
 
            if ( yc[i] > ( xc[i] || 0 ) ) {
                e--;
            }
 
            if ( pr == null ) {
                s = pr = Decimal['precision'];
                rm = Decimal['rounding'];
            } else if (dp) {
                s = pr + ( x['e'] - y['e'] ) + 1;
            } else {
                s = pr;
            }
 
            if ( s < 0 ) {
                qc.push(1);
                more = true;
            } else {
 
                // Convert base 10 decimal places to base 1e7 decimal places.
                s = s / logbase + 2 | 0;
                i = 0;
 
                // divisor < 1e7
                if ( yL == 1 ) {
                    n = 0;
                    yc = yc[0];
                    s++;
 
                    // 'n' is the carry.
                    for ( ; ( i < xL || n ) && s--; i++ ) {
                        t = n * base + ( xc[i] || 0 );
                        qc[i] = t / yc | 0;
                        n = t % yc | 0;
                    }
 
                    more = n || i < xL;
 
                // divisor >= 1e7
                } else {
 
                    // Normalise xc and yc so highest order digit of yc is >= base/2
                    n = base / ( yc[0] + 1 ) | 0;
 
                    if ( n > 1 ) {
                        yc = multiplyInteger( yc, n, base );
                        xc = multiplyInteger( xc, n, base );
                        yL = yc.length;
                        xL = xc.length;
                    }
 
                    xi = yL;
                    rem = xc.slice( 0, yL );
                    remL = rem.length;
 
                    // Add zeros to make remainder as long as divisor.
                    for ( ; remL < yL; rem[remL++] = 0 );
 
                    yz = yc.slice();
                    yz.unshift(0);
                    yc0 = yc[0];
 
                    if ( yc[1] >= base / 2 ) {
                        yc0++;
                    }
 
                    do {
                        n = 0;
 
                        // Compare divisor and remainder.
                        cmp = compare( yc, rem, yL, remL );
 
                        // If divisor < remainder.
                        if ( cmp < 0 ) {
 
                            // Calculate trial digit, n.
                            rem0 = rem[0];
 
                            if ( yL != remL ) {
                                rem0 = rem0 * base + ( rem[1] || 0 );
                            }
 
                            // n will be how many times the divisor goes into the current remainder.
                            n = rem0 / yc0 | 0;
 
                            /*
                              Algorithm:
                              1. product = divisor * trial digit (n)
                              2. if product > remainder: product -= divisor, n--
                              3. remainder -= product
                              4. if product was < remainder at 2:
                                5. compare new remainder and divisor
                                6. If remainder > divisor: remainder -= divisor, n++
                            */
 
                            if ( n > 1 ) {
 
                                if ( n >= base ) {
                                    n = base - 1;
                                }
 
                                // product = divisor * trial digit.
                                prod = multiplyInteger( yc, n, base );
                                prodL = prod.length;
                                remL = rem.length;
 
                                // Compare product and remainder.
                                cmp = compare( prod, rem, prodL, remL );
 
                                // product > remainder.
                                if ( cmp == 1 ) {
                                    n--;
 
                                    // Subtract divisor from product.
                                    subtract( prod, yL < prodL ? yz : yc, prodL, base );
                                }
                            } else {
 
                                // cmp is -1.
                                // If n is 0, there is no need to compare yc and rem again below, so change cmp to 1 to avoid it.
                                // If n is 1 there IS a need to compare yc and rem again below.
                                if ( n == 0 ) {
                                    cmp = n = 1;
                                }
                                prod = yc.slice();
                            }
                            prodL = prod.length;
 
                            if ( prodL < remL ) {
                                prod.unshift(0);
                            }
 
                            // Subtract product from remainder.
                            subtract( rem, prod, remL, base );
 
                            // If product was < previous remainder.
                            if ( cmp == -1 ) {
                                remL = rem.length;
 
                                // Compare divisor and new remainder.
                                cmp = compare( yc, rem, yL, remL );
 
                                // If divisor < new remainder, subtract divisor from remainder.
                                if ( cmp < 1 ) {
                                    n++;
 
                                    // Subtract divisor from remainder.
                                    subtract( rem, yL < remL ? yz : yc, remL, base );
                                }
                            }
 
                            remL = rem.length;
 
                        } else if ( cmp === 0 ) {
                            n++;
                            rem = [0];
                        }    // if cmp === 1, n will be 0
 
                        // Add the next digit, n, to the result array.
                        qc[i++] = n;
 
                        // Update the remainder.
                        if ( cmp && rem[0] ) {
                            rem[remL++] = xc[xi] || 0;
                        } else {
                            rem = [ xc[xi] ];
                            remL = 1;
                        }
 
                    } while ( ( xi++ < xL || rem[0] != null ) && s-- );
 
                    more = rem[0] != null;
                }
 
                // Leading zero?
                if ( !qc[0] ) {
                    qc.shift();
                }
            }
 
            // If div is being used for base conversion.
            if ( logbase == 1 ) {
                q['e'] = e;
                q['r'] = +more;
            } else {
 
                // To calculate q.e, first get the number of digits of qc[0].
                for ( i = 1, s = qc[0]; s >= 10; s /= 10, i++ );
                q['e'] = i + e * logbase - 1;
 
                rnd( q, dp ? pr + q['e'] + 1 : pr, rm, more );
            }
 
            return q;
        };
    })();
 
 
    /*
     * Taylor/Maclaurin series.
     *
     * exp(x) = x^0/0! + x^1/1! + x^2/2! + x^3/3! + ...
     *
     * Argument reduction:
     *   Repeat x = x / 32, k += 5, until |x| < 0.1
     *   exp(x) = exp(x / 2^k)^(2^k)
     *
     * Previously, the argument was initially reduced by
     * exp(x) = exp(r) * 10^k  where r = x - k * ln10, k = floor(x / ln10)
     * to first put r in the range [0, ln10], before dividing by 32 until |x| < 0.1, but this was
     * found to be slower than just dividing repeatedly by 32 as above.
     *
     * Max integer argument: exp('20723265836946413') = 6.3e+9000000000000000
     * Min integer argument: exp('-20723265836946411') = 1.2e-9000000000000000
     * ( Math object integer min/max: Math.exp(709) = 8.2e+307, Math.exp(-745) = 5e-324 )
     *
     *  exp(Infinity)  = Infinity
     *  exp(-Infinity) = 0
     *  exp(NaN)       = NaN
     *  exp(+-0)       = 1
     *
     *  exp(x) is non-terminating for any finite, non-zero x.
     *
     *  The result will always be correctly rounded.
     *
     */
    function exp( x, pr ) {
        var denom, guard, j, pow, sd, sum, t,
            rep = 0,
            i = 0,
            k = 0,
            Decimal = x['constructor'],
            one = Decimal['ONE'],
            rm = Decimal['rounding'],
            precision = Decimal['precision'];
 
        // 0/NaN/Infinity?
        if ( !x['c'] || !x['c'][0] || x['e'] > 17 ) {
 
            return new Decimal( x['c']
              ? !x['c'][0] ? one : x['s'] < 0 ? 0 : 1 / 0
              : x['s'] ? x['s'] < 0 ? 0 : x : NaN );
        }
 
        if ( pr == null ) {
 
            /*
             Estimate result exponent.
             e^x = 10^j, where j = x * log10(e) and
             log10(e) = ln(e) / ln(10) = 1 / ln(10),
             so j = x / ln(10)
            j = mathfloor( x / Math.LN10 );
 
            // Overflow/underflow? Estimate may be +-1 of true value.
            if ( j > Decimal['maxE'] + 1 || j < Decimal['minE'] - 1 ) {
 
                return new Decimal( j > 0 ? 1 / 0 : 0 );
            }
             */
 
            external = false;
            sd = precision;
        } else {
            sd = pr;
        }
 
        t = new Decimal(0.03125);
 
        // while abs(x) >= 0.1
        while ( x['e'] > -2 ) {
 
            // x = x / 2^5
            x = x['times'](t);
            k += 5;
        }
 
        /*
         Use 2 * log10(2^k) + 5 to estimate the increase in precision necessary to ensure the first
         4 rounding digits are correct.
         */
        guard = Math.log( mathpow( 2, k ) ) / Math.LN10 * 2 + 5 | 0;
        sd += guard;
 
        denom = pow = sum = new Decimal(one);
        Decimal['precision'] = sd;
 
        for ( ; ; ) {
            pow = rnd( pow['times'](x), sd, 1 );
            denom = denom['times'](++i);
            t = sum['plus']( div( pow, denom, sd, 1 ) );
 
            if ( coefficientToString( t['c'] ).slice( 0, sd ) ===
                 coefficientToString( sum['c'] ).slice( 0, sd ) ) {
                j = k;
 
                while ( j-- ) {
                    sum = rnd( sum['times'](sum), sd, 1 );
                }
 
                /*
                 Check to see if the first 4 rounding digits are [49]999.
                 If so, repeat the summation with a higher precision, otherwise
                 E.g. with precision: 18, rounding: 1
                 exp(18.404272462595034083567793919843761) = 98372560.1229999999
                                           when it should be 98372560.123
 
                 sd - guard is the index of first rounding digit.
                 */
                if ( pr == null ) {
 
                    if ( rep < 3 && checkRoundingDigits( sum['c'], sd - guard, rm, rep ) ) {
                        Decimal['precision'] = sd += 10;
                        denom = pow = t = new Decimal(one);
                        i = 0;
                        rep++;
                    } else {
 
                        return rnd( sum, Decimal['precision'] = precision, rm, external = true );
                    }
                } else {
                    Decimal['precision'] = precision;
 
                    return sum;
                }
            }
            sum = t;
        }
    }
 
 
    /*
     * Return a string representing the value of Decimal n in normal or exponential notation
     * rounded to the specified decimal places or significant digits.
     * Called by toString, toExponential (k is 1), toFixed, and toPrecision (k is 2).
     * i is the index (with the value in normal notation) of the digit that may be rounded up.
     * j is the rounding mode, then the number of digits required including fraction-part trailing
     * zeros.
     */
    function format( n, i, j, k ) {
        var s, z,
            Decimal = n['constructor'],
            e = ( n = new Decimal(n) )['e'];
 
        // i == null when toExponential(no arg), or toString() when x >= toExpPos etc.
        if ( i == null ) {
            j = 0;
        } else {
            rnd( n, ++i, j );
 
            // If toFixed, n['e'] may have changed if the value was rounded up.
            j = k ? i : i + n['e'] - e;
        }
 
        e = n['e'];
        s = coefficientToString( n['c'] );
 
        /*
         toPrecision returns exponential notation if the number of significant digits specified
         is less than the number of digits necessary to represent the integer part of the value
         in normal notation.
         */
 
        // Exponential notation.
        if ( k == 1 || k == 2 && ( i <= e || e <= Decimal['toExpNeg'] ) ) {
 
            // Append zeros?
            for ( ; s.length < j; s += '0' );
 
            if ( s.length > 1 ) {
                s = s.charAt(0) + '.' + s.slice(1);
            }
 
            s += ( e < 0 ? 'e' : 'e+' ) + e;
 
        // Normal notation.
        } else {
            k = s.length;
 
            // Negative exponent?
            if ( e < 0 ) {
                z = j - k;
 
                // Prepend zeros.
                for ( ; ++e; s = '0' + s );
                s = '0.' + s;
 
            // Positive exponent?
            } else {
 
                if ( ++e > k ) {
                    z = j - e;
 
                    // Append zeros.
                    for ( e -= k; e-- ; s += '0' );
 
                    if ( z > 0 ) {
                        s += '.';
                    }
 
                } else {
                    z = j - k;
 
                    if ( e < k ) {
                        s = s.slice( 0, e ) + '.' + s.slice(e);
                    } else if ( z > 0 ) {
                        s += '.';
                    }
                }
            }
 
            // Append more zeros?
            if ( z > 0 ) {
 
                for ( ; z--; s += '0' );
            }
        }
 
        return n['s'] < 0 && n['c'][0] ? '-' + s : s;
    }
 
 
    function getCoeffLength(c) {
        var v = c.length - 1,
            n = v * LOGBASE + 1;
 
        if ( v = c[v] ) {
 
            // Subtract the number of trailing zeros of the last number.
            for ( ; v % 10 == 0; v /= 10, n-- );
 
            // Add the number of digits of the first number.
            for ( v = c[0]; v >= 10; v /= 10, n++ );
        }
 
        return n;
    }
 
 
    /*
     * Assemble error messages. Throw Decimal Errors.
     */
    function ifExceptionsThrow( Decimal, message, arg, method, more ) {
 
        if ( Decimal['errors'] ) {
            var error = new Error( ( method || [
              'new Decimal', 'cmp', 'div', 'eq', 'gt', 'gte', 'lt', 'lte', 'minus', 'mod',
              'plus', 'times', 'toFraction', 'pow', 'random', 'log', 'sqrt', 'toNearest', 'divToInt'
              ][ id ? id < 0 ? -id : id : 1 / id < 0 ? 1 : 0 ] ) + '() ' + ( [
              'number type has more than 15 significant digits', 'LN10 out of digits' ][message]
              || message + ( [ outOfRange ? ' out of range' : ' not an integer',
              ' not a boolean or binary digit' ][more] || '' ) ) + ': ' + arg
            );
            error['name'] = 'Decimal Error';
            outOfRange = id = 0;
 
            throw error;
        }
    }
 
 
    /*
     * Use 'exponentiation by squaring' for small integers. Called by convertBase and pow.
     */
    function intPow( Decimal, x, i ) {
        var r = new Decimal( Decimal['ONE'] );
 
        for ( external = false; ; ) {
 
            if ( i & 1 ) {
                r = r['times'](x);
            }
            i >>= 1;
 
            if ( !i ) {
 
                break;
            }
            x = x['times'](x);
        }
        external = true;
 
        return r;
    }
 
 
    /*
     *  ln(-n)        = NaN
     *  ln(0)         = -Infinity
     *  ln(-0)        = -Infinity
     *  ln(1)         = 0
     *  ln(Infinity)  = Infinity
     *  ln(-Infinity) = NaN
     *  ln(NaN)       = NaN
     *
     *  ln(n) (n != 1) is non-terminating.
     *
     */
    function ln( y, pr ) {
        var c, c0, denom, e, num, rep, sd, sum, t, x1, x2,
            n = 1,
            guard = 10,
            x = y,
            xc = x['c'],
            Decimal = x['constructor'],
            one = Decimal['ONE'],
            rm = Decimal['rounding'],
            precision = Decimal['precision'];
 
        // x < 0 or +-Infinity/NaN or 0 or 1.
        if ( x['s'] < 0 || !xc || !xc[0] || !x['e'] && xc[0] == 1 && xc.length == 1 ) {
 
            return new Decimal( xc && !xc[0] ? -1 / 0 : x['s'] != 1 ? NaN : xc ? 0 : x );
        }
 
        if ( pr == null ) {
            external = false;
            sd = precision;
        } else {
            sd = pr;
        }
 
        Decimal['precision'] = sd += guard;
 
        c = coefficientToString(xc);
        c0 = c.charAt(0);
 
        if ( Math.abs( e = x['e'] ) < 1.5e15 ) {
 
            /*
             Argument reduction.
             The series converges faster the closer the argument is to 1, so using
             ln(a^b) = b * ln(a),   ln(a) = ln(a^b) / b
             multiply the argument by itself until the leading digits of the significand are 7, 8,
             9, 10, 11, 12 or 13, recording the number of multiplications so the sum of the series
             can later be divided by this number, then separate out the power of 10 using
             ln(a*10^b) = ln(a) + b*ln(10).
             */
 
            // max n is 21 ( gives 0.9, 1.0 or 1.1 ) ( 9e15 / 21 = 4.2e14 ).
            //while ( c0 < 9 && c0 != 1 || c0 == 1 && c.charAt(1) > 1 ) {
            // max n is 6 ( gives 0.7 - 1.3 )
            while ( c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3 ) {
                x = x['times'](y);
                c = coefficientToString( x['c'] );
                c0 = c.charAt(0);
                n++;
            }
 
            e = x['e'];
 
            if ( c0 > 1 ) {
                x = new Decimal( '0.' + c );
                e++;
            } else {
                x = new Decimal( c0 + '.' + c.slice(1) );
            }
        } else {
 
            /*
             The argument reduction method above may result in overflow if the argument y is a
             massive number with exponent >= 1500000000000000 ( 9e15 / 6 = 1.5e15 ), so instead
             recall this function using ln(x*10^e) = ln(x) + e*ln(10).
             */
            x = new Decimal( c0 + '.' + c.slice(1) );
 
            Iif ( sd + 2 > LN10.length ) {
                ifExceptionsThrow( Decimal, 1, sd + 2, 'ln' );
            }
 
            x = ln( x, sd - guard )['plus'](
                new Decimal( LN10.slice( 0, sd + 2 ) )['times']( e + '' )
            );
 
            Decimal['precision'] = precision;
 
            return pr == null ? rnd( x, precision, rm, external = true ) : x;
        }
 
        // x1 is x reduced to a value near 1.
        x1 = x;
 
        /*
         Taylor series.
         ln(y) = ln( (1 + x)/(1 - x) ) = 2( x + x^3/3 + x^5/5 + x^7/7 + ... )
         where
         x = (y - 1)/(y + 1)              ( |x| < 1 )
         */
        sum = num = x = div( x['minus'](one), x['plus'](one), sd, 1 );
        x2 = rnd( x['times'](x), sd, 1 );
        denom = 3;
 
        for ( ; ; ) {
            num = rnd( num['times'](x2), sd, 1 );
            t = sum['plus']( div( num, new Decimal(denom), sd, 1 ) );
 
            if ( coefficientToString( t['c'] ).slice( 0, sd ) ===
                 coefficientToString( sum['c'] ).slice( 0, sd ) ) {
                sum = sum['times'](2);
 
                /*
                 Reverse the argument reduction. Check that e is not 0 because, as well as
                 preventing an unnecessary calculation, -0 + 0 = +0 and to ensure correct
                 rounding later -0 needs to stay -0.
                 */
                if ( e !== 0 ) {
 
                    Iif ( sd + 2 > LN10.length ) {
                        ifExceptionsThrow( Decimal, 1, sd + 2, 'ln' );
                    }
 
                    sum = sum['plus'](
                        new Decimal( LN10.slice( 0, sd + 2 ) )['times']( e + '' )
                    );
                }
 
                sum = div( sum, new Decimal(n), sd, 1 );
 
                /*
                 Is rm > 3 and the first 4 rounding digits 4999, or rm < 4 (or the summation has
                 been repeated previously) and the first 4 rounding digits 9999?
 
                 If so, restart the summation with a higher precision, otherwise
                 e.g. with precision: 12, rounding: 1
                 ln(135520028.6126091714265381533) = 18.7246299999 when it should be 18.72463.
 
                 sd - guard is the index of first rounding digit.
                 */
                if ( pr == null ) {
 
                    if ( checkRoundingDigits( sum['c'], sd - guard, rm, rep ) ) {
                        Decimal['precision'] = sd += guard;
                        t = num = x = div( x1['minus'](one), x1['plus'](one), sd, 1 );
                        x2 = rnd( x['times'](x), sd, 1 );
                        denom = rep = 1;
                    } else {
 
                        return rnd( sum, Decimal['precision'] = precision, rm, external = true );
                    }
                } else {
                    Decimal['precision'] = precision;
 
                    return sum;
                }
            }
 
            sum = t;
            denom += 2;
        }
    }
 
 
    /*
     * Round x to sd significant digits using rounding mode rm. Check for over/under-flow.
     */
     function rnd( x, sd, rm, r ) {
        var digits, i, j, k, n, rd, xc, xci,
            Decimal = x['constructor'];
 
        // Don't round if sd is null or undefined.
        out: if ( sd != null ) {
 
            // Infinity/NaN.
            if ( !( xc = x['c'] ) ) {
 
                return x;
            }
 
            /*
             rd, the rounding digit, i.e. the digit after the digit that may be rounded up,
             n, a base 1e7 number, the element of xc containing rd,
             xci, the index of n within xc,
             digits, the number of digits of n,
             i, what would be the index of rd within n if all the numbers were 7 digits long (i.e. they had leading zeros)
             j, if > 0, the actual index of rd within n (if < 0, rd is a leading zero),
             nLeadingZeros, the number of leading zeros n would have if it were 7 digits long.
             */
 
            // Get the length of the first element of the coefficient array xc.
            for ( digits = 1, k = xc[0]; k >= 10; k /= 10, digits++ );
 
            i = sd - digits;
 
            // Is the rounding digit in the first element of xc?
            if ( i < 0 ) {
                i += LOGBASE;
                j = sd;
                n = xc[ xci = 0 ];
 
                // Get the rounding digit at index j of n.
                rd = n / mathpow( 10, digits - j - 1 ) % 10 | 0;
            } else {
                xci = Math.ceil( ( i + 1 ) / LOGBASE );
 
                if ( xci >= xc.length ) {
 
                    if (r) {
 
                        // Needed by exp, ln and sqrt.
                        for ( ; xc.length <= xci; xc.push(0) );
 
                        n = rd = 0;
                        digits = 1;
                        i %= LOGBASE;
                        j = i - LOGBASE + 1;
                    } else {
 
                      break out;
                    }
                } else {
                    n = k = xc[xci];
 
                    // Get the number of digits of n.
                    for ( digits = 1; k >= 10; k /= 10, digits++ );
 
                    // Get the index of rd within n.
                    i %= LOGBASE;
 
                    // Get the index of rd within n, adjusted for leading zeros.
                    // The number of leading zeros of n is given by LOGBASE - digits.
                    j = i - LOGBASE + digits;
 
                    // Get the rounding digit at index j of n.
                    // Floor using Math.floor instead of | 0 as rd may be outside int range.
                    rd = j < 0 ? 0 : mathfloor( n / mathpow( 10, digits - j - 1 ) % 10 );
                }
            }
 
            r = r || sd < 0 ||
              // Are there any non-zero digits after the rounding digit?
              xc[xci + 1] != null || ( j < 0 ? n : n % mathpow( 10, digits - j - 1 ) );
 
            /*
             The expression  n % mathpow( 10, digits - j - 1 )  returns all the digits of n to the
             right of the digit at (left-to-right) index j,
             e.g. if n is 908714 and j is 2, the expression will give 714.
             */
 
            r = rm < 4
              ? ( rd || r ) && ( rm == 0 || rm == ( x['s'] < 0 ? 3 : 2 ) )
              : rd > 5 || rd == 5 && ( rm == 4 || r ||
                // Check whether the digit to the left of the rounding digit is odd.
                rm == 6 && ( ( i > 0 ? j > 0 ? n / mathpow( 10, digits - j ) : 0 : xc[xci - 1] ) % 10 ) & 1 ||
                  rm == ( x['s'] < 0 ? 8 : 7 ) );
 
            if ( sd < 1 || !xc[0] ) {
                xc.length = 0;
 
                if (r) {
 
                    // Convert sd to decimal places.
                    sd -= x['e'] + 1;
 
                    // 1, 0.1, 0.01, 0.001, 0.0001 etc.
                    xc[0] = mathpow( 10, sd % LOGBASE );
                    x['e'] = -sd || 0;
                } else {
 
                    // Zero.
                    xc[0] = x['e'] = 0;
                }
 
                return x;
            }
 
            // Remove excess digits.
 
            if ( i == 0 ) {
                xc.length = xci;
                k = 1;
                xci--;
            } else {
                xc.length = xci + 1;
                k = mathpow( 10, LOGBASE - i );
 
                // E.g. 56700 becomes 56000 if 7 is the rounding digit.
                // j > 0 means i > number of leading zeros of n.
                xc[xci] = j > 0 ? ( n / mathpow( 10, digits - j ) % mathpow( 10, j ) | 0 ) * k : 0;
            }
 
            // Round up?
            if (r) {
 
                for ( ; ; ) {
 
                    // Is the digit to be rounded up in the first element of xc?
                    if ( xci == 0 ) {
 
                        // i will be the length of xc[0] before k is added.
                        for ( i = 1, j = xc[0]; j >= 10; j /= 10, i++ );
 
                        j = xc[0] += k;
 
                        for ( k = 1; j >= 10; j /= 10, k++ );
 
                        // if i != k the length has increased.
                        if ( i != k ) {
                            x['e']++;
 
                            if ( xc[0] == BASE ) {
                                xc[0] = 1;
                            }
                        }
 
                        break;
                    } else {
                        xc[xci] += k;
 
                        if ( xc[xci] != BASE ) {
 
                            break;
                        }
 
                        xc[xci--] = 0;
                        k = 1;
                    }
                }
            }
 
            // Remove trailing zeros.
            for ( i = xc.length; xc[--i] === 0; xc.pop() );
        }
 
        if (external) {
 
            // Overflow?
            if ( x['e'] > Decimal['maxE'] ) {
 
                // Infinity.
                x['c'] = x['e'] = null;
 
            // Underflow?
            } else if ( x['e'] < Decimal['minE'] ) {
 
                // Zero.
                x['c'] = [ x['e'] = 0 ];
            }
        }
 
        return x;
    }
 
 
    decimal = (function () {
 
 
        // Private functions used by static Decimal methods.
 
 
        /*
         *  The following emulations or wrappers of Math object functions are currently
         *  commented-out and not in the public API.
         *
         *  abs
         *  acos
         *  asin
         *  atan
         *  atan2
         *  ceil
         *  cos
         *  floor
         *  round
         *  sin
         *  tan
         *  trunc
         */
 
 
        /*
         * Return a new Decimal whose value is the absolute value of n.
         *
         * n {number|string|Decimal}
         *
        function abs(n) { return new this(n)['abs']() }
         */
 
 
        /*
         * Return a new Decimal whose value is the arccosine in radians of n.
         *
         * n {number|string|Decimal}
         *
        function acos(n) { return new this( Math.acos(n) + '' ) }
         */
 
 
        /*
         * Return a new Decimal whose value is the arcsine in radians of n.
         *
         * n {number|string|Decimal}
         *
        function asin(n) { return new this( Math.asin(n) + '' ) }
         */
 
 
        /*
         * Return a new Decimal whose value is the arctangent in radians of n.
         *
         * n {number|string|Decimal}
         *
        function atan(n) { return new this( Math.atan(n) + '' ) }
         */
 
 
        /*
         * Return a new Decimal whose value is the arctangent in radians of y/x in the range
         * -PI to PI (inclusive).
         *
         * y {number|string|Decimal} The y-coordinate.
         * x {number|string|Decimal} The x-coordinate.
         *
        function atan2( y, x ) { return new this( Math.atan2( y, x ) + '' ) }
         */
 
 
        /*
         * Return a new Decimal whose value is n round to an integer using ROUND_CEIL.
         *
         * n {number|string|Decimal}
         *
        function ceil(n) { return new this(n)['ceil']() }
         */
 
 
        /*
         * Configure global settings for a Decimal constructor.
         *
         * obj is an object with any of the following properties,
         *
         *   precision  {number}
         *   rounding   {number}
         *   toExpNeg   {number}
         *   toExpPos   {number}
         *   minE       {number}
         *   maxE       {number}
         *   errors     {boolean|number}
         *   crypto     {boolean|number}
         *   modulo     {number}
         *
         *   format     {object}     See Decimal.prototype.toFormat
         *      decimalSeparator       {string}
         *      groupSeparator         {string}
         *      groupSize              {number}
         *      secondaryGroupSize     {number}
         *      fractionGroupSeparator {string}
         *      fractionGroupSize      {number}
         *
         *   A format object will replace the existing Decimal.format object without any property
         *   checking.
         *
         * E.g.
         *   Decimal.config({ precision: 20, rounding: 4 })
         *
         */
        function config(obj) {
            var p, u, v,
                Decimal = this,
                c = 'config',
                parse = Decimal['errors'] ? parseInt : parseFloat;
 
            if ( obj == u || typeof obj != 'object' &&
              // 'config() object expected: {obj}'
              !ifExceptionsThrow( Decimal, 'object expected', obj, c ) ) {
 
                return Decimal;
            }
 
            // precision {number} Integer, 1 to MAX_DIGITS inclusive.
            if ( ( v = obj[ p = 'precision' ] ) != u ) {
 
                if ( !( outOfRange = v < 1 || v > MAX_DIGITS ) && parse(v) == v ) {
                    Decimal[p] = v | 0;
                } else {
 
                    // 'config() precision not an integer: {v}'
                    // 'config() precision out of range: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 0 );
                }
            }
 
            // rounding {number} Integer, 0 to 8 inclusive.
            if ( ( v = obj[ p = 'rounding' ] ) != u ) {
 
                if ( !( outOfRange = v < 0 || v > 8 ) && parse(v) == v ) {
                    Decimal[p] = v | 0;
                } else {
 
                    // 'config() rounding not an integer: {v}'
                    // 'config() rounding out of range: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 0 );
                }
            }
 
            // toExpNeg {number} Integer, -EXP_LIMIT to 0 inclusive.
            if ( ( v = obj[ p = 'toExpNeg' ] ) != u ) {
 
                if ( !( outOfRange = v < -EXP_LIMIT || v > 0 ) && parse(v) == v ) {
                    Decimal[p] = mathfloor(v);
                } else {
 
                    // 'config() toExpNeg not an integer: {v}'
                    // 'config() toExpNeg out of range: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 0 );
                }
            }
 
            // toExpPos {number} Integer, 0 to EXP_LIMIT inclusive.
            if ( ( v = obj[ p = 'toExpPos' ] ) != u ) {
 
                if ( !( outOfRange = v < 0 || v > EXP_LIMIT ) && parse(v) == v ) {
                    Decimal[p] = mathfloor(v);
                } else {
 
                    // 'config() toExpPos not an integer: {v}'
                    // 'config() toExpPos out of range: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 0 );
                }
            }
 
             // minE {number} Integer, -EXP_LIMIT to 0 inclusive.
            if ( ( v = obj[ p = 'minE' ] ) != u ) {
 
                if ( !( outOfRange = v < -EXP_LIMIT || v > 0 ) && parse(v) == v ) {
                    Decimal[p] = mathfloor(v);
                } else {
 
                    // 'config() minE not an integer: {v}'
                    // 'config() minE out of range: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 0 );
                }
            }
 
            // maxE {number} Integer, 0 to EXP_LIMIT inclusive.
            if ( ( v = obj[ p = 'maxE' ] ) != u ) {
 
                if ( !( outOfRange = v < 0 || v > EXP_LIMIT ) && parse(v) == v ) {
                    Decimal[p] = mathfloor(v);
                } else {
 
                    // 'config() maxE not an integer: {v}'
                    // 'config() maxE out of range: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 0 );
                }
            }
 
            // errors {boolean|number} true, false, 1 or 0.
            if ( ( v = obj[ p = 'errors' ] ) != u ) {
 
                if ( v === !!v || v === 1 || v === 0 ) {
                    outOfRange = id = 0;
                    Decimal[p] = !!v;
                } else {
 
                    // 'config() errors not a boolean or binary digit: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 1 );
                }
            }
 
            // crypto {boolean|number} true, false, 1 or 0.
            if ( ( v = obj[ p = 'crypto' ] ) != u ) {
 
                if ( v === !!v || v === 1 || v === 0 ) {
                    Decimal[p] = !!( v && crypto && typeof crypto == 'object' );
                } else {
 
                    // 'config() crypto not a boolean or binary digit: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 1 );
                }
            }
 
            // modulo {number} Integer, 0 to 9 inclusive.
            if ( ( v = obj[ p = 'modulo' ] ) != u ) {
 
                if ( !( outOfRange = v < 0 || v > 9 ) && parse(v) == v ) {
                    Decimal[p] = v | 0;
                } else {
 
                    // 'config() modulo not an integer: {v}'
                    // 'config() modulo out of range: {v}'
                    ifExceptionsThrow( Decimal, p, v, c, 0 );
                }
            }
 
            // format {object}
            if ( ( obj = obj[ p = 'format' ] ) != u ) {
 
                Eif ( typeof obj == 'object' ) {
                    Decimal[p] = obj;
                } else {
 
                    // 'config() format object expected: {obj}'
                    ifExceptionsThrow( Decimal, 'format object expected', obj, c );
                }
            }
 
            return Decimal;
        }
 
 
        /*
         * Return a new Decimal whose value is the cosine of n.
         *
         * n {number|string|Decimal} A number given in radians.
         *
        function cos(n) { return new this( Math.cos(n) + '' ) }
         */
 
 
        /*
         * Return a new Decimal whose value is the exponential of n,
         *
         * n {number|string|Decimal} The power to which to raise the base of the natural log.
         *
         */
        function exp(n) { return new this(n)['exp'](); }
 
 
        /*
         * Return a new Decimal whose value is n round to an integer using ROUND_FLOOR.
         *
         * n {number|string|Decimal}
         *
        function floor(n) { return new this(n)['floor']() }
         */
 
 
        /*
         * Return a new Decimal whose value is the natural logarithm of n.
         *
         * n {number|string|Decimal}
         *
         */
        function ln(n) { return new this(n)['ln'](); }
 
 
        /*
         * Return a new Decimal whose value is the log of x to the base y, or to base 10 if no
         * base is specified.
         *
         * log[y](x)
         *
         * x {number|string|Decimal} The argument of the logarithm.
         * y {number|string|Decimal} The base of the logarithm.
         *
         */
        function log( x, y ) { return new this(x)['log'](y); }
 
 
        /*
         * Handle max and min. ltgt is 'lt' or 'gt'.
         */
        function maxOrMin( Decimal, args, ltgt ) {
            var m, n,
                i = 0;
 
            if ( toString.call( args[0] ) == '[object Array]' ) {
                args = args[0];
            }
 
            m = new Decimal( args[0] );
 
            for ( ; ++i < args.length; ) {
                n = new Decimal( args[i] );
 
                if ( !n['s'] ) {
                    m = n;
 
                    break;
                } else if ( m[ltgt](n) ) {
                    m = n;
                }
            }
 
            return m;
        }
 
 
        /*
         * Return a new Decimal whose value is the maximum of the arguments.
         *
         * arguments {number|string|Decimal}
         *
         */
        function max() { return maxOrMin( this, arguments, 'lt' ); }
 
 
        /*
         * Return a new Decimal whose value is the minimum of the arguments.
         *
         * arguments {number|string|Decimal}
         *
         */
        function min() { return maxOrMin( this, arguments, 'gt' ); }
 
 
        /*
         * Parse the value of a new Decimal from a number or string.
         */
        var parseDecimal = (function () {
            var isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,
                trim = String.prototype.trim ||
                  function () { return this.replace(/^\s+|\s+$/g, ''); };
 
            return function ( Decimal, x, n, b ) {
                var d, e, i, isNum, orig, valid;
 
                if ( typeof n != 'string' ) {
 
                    // If n is a number, check if minus zero.
                    n = ( isNum = typeof n == 'number' || toString.call(n) == '[object Number]' ) &&
                        n === 0 && 1 / n < 0 ? '-0' : n + '';
                }
                orig = n;
 
                if ( b == null && isValid.test(n) ) {
 
                    // Determine sign.
                    x['s'] = n.charCodeAt(0) === 45 ? ( n = n.slice(1), -1 ) : 1;
 
                // Either n is not a valid Decimal or a base has been specified.
                } else {
 
                    /*
                     Enable exponential notation to be used with base 10 argument.
                     Ensure return value is rounded to precision as with other bases.
                     */
                    if ( b == 10 ) {
 
                        return rnd( new Decimal(n), Decimal['precision'], Decimal['rounding'] );
                    }
 
                    n = trim.call(n).replace( /^\+(?!-)/, '' );
 
                    x['s'] = n.charCodeAt(0) === 45 ? ( n = n.replace( /^-(?!-)/, '' ), -1 ) : 1;
 
                    if ( b != null ) {
 
                        if ( ( b == (b | 0) || !Decimal['errors'] ) &&
                          !( outOfRange = !( b >= 2 && b < 65 ) ) ) {
                            d = '[' + NUMERALS.slice( 0, b = b | 0 ) + ']+';
 
                           // Remove the `.` from e.g. '1.', and replace e.g. '.1' with '0.1'.
                            n = n.replace( /\.$/, '' ).replace( /^\./, '0.' );
 
                            // Any number in exponential form will fail due to the e+/-.
                            if ( valid = new RegExp(
                              '^' + d + '(?:\\.' + d + ')?$', b < 37 ? 'i' : '' ).test(n) ) {
 
                                if (isNum) {
 
                                    Iif ( n.replace( /^0\.0*|\./, '' ).length > 15 ) {
 
                                        // '{method} number type has more than 15 significant digits: {n}'
                                        ifExceptionsThrow( Decimal, 0, orig );
                                    }
 
                                    // Prevent later check for length on converted number.
                                    isNum = !isNum;
                                }
                                n = convertBase( Decimal, n, 10, b, x['s'] );
 
                            } else if ( n != 'Infinity' && n != 'NaN' ) {
 
                                // '{method} not a base {b} number: {n}'
                                ifExceptionsThrow( Decimal, 'not a base ' + b + ' number', orig );
                                n = 'NaN';
                            }
                        } else {
 
                            // '{method} base not an integer: {b}'
                            // '{method} base out of range: {b}'
                            ifExceptionsThrow( Decimal, 'base', b, 0, 0 );
 
                            // Ignore base.
                            valid = isValid.test(n);
                        }
                    } else {
                        valid = isValid.test(n);
                    }
 
                    if ( !valid ) {
 
                        // Infinity/NaN
                        x['c'] = x['e'] = null;
 
                        // NaN
                        if ( n != 'Infinity' ) {
 
                            // No exception on NaN.
                            if ( n != 'NaN' ) {
 
                                // '{method} not a number: {n}'
                                ifExceptionsThrow( Decimal, 'not a number', orig );
                            }
                            x['s'] = null;
                        }
                        id = 0;
 
                        return x;
                    }
                }
 
                // Decimal point?
                if ( ( e = n.indexOf('.') ) > -1 ) {
                    n = n.replace( '.', '' );
                }
 
                // Exponential form?
                if ( ( i = n.search(/e/i) ) > 0 ) {
 
                    // Determine exponent.
                    if ( e < 0 ) {
                        e = i;
                    }
                    e += +n.slice( i + 1 );
                    n = n.substring( 0, i );
 
                } else if ( e < 0 ) {
 
                    // Integer.
                    e = n.length;
                }
 
                // Determine leading zeros.
                for ( i = 0; n.charCodeAt(i) === 48; i++ );
 
                // Determine trailing zeros.
                for ( b = n.length; n.charCodeAt(--b) === 48; );
 
                n = n.slice( i, b + 1 );
 
                if (n) {
                    b = n.length;
 
                    // Disallow numbers with over 15 significant digits if number type.
                    if ( isNum && b > 15 ) {
 
                        // '{method} number type has more than 15 significant digits: {n}'
                        ifExceptionsThrow( Decimal, 0, orig );
                    }
 
                    x['e'] = e = e - i - 1;
                    x['c'] = [];
 
                    // Transform base
 
                    // e is the base 10 exponent.
                    // i is where to slice n to get the first element of the coefficient array.
                    i = ( e + 1 ) % LOGBASE;
 
                    if ( e < 0 ) {
                        i += LOGBASE;
                    }
 
                    // b is n.length.
                    if ( i < b ) {
 
                        if (i) {
                            x['c'].push( +n.slice( 0, i ) );
                        }
 
                        for ( b -= LOGBASE; i < b; ) {
                            x['c'].push( +n.slice( i, i += LOGBASE ) );
                        }
 
                        n = n.slice(i);
                        i = LOGBASE - n.length;
                    } else {
                        i -= b;
                    }
 
                    for ( ; i--; n += '0' );
 
                    x['c'].push( +n );
 
                    if (external) {
 
                        // Overflow?
                        if ( x['e'] > Decimal['maxE'] ) {
 
                            // Infinity.
                            x['c'] = x['e'] = null;
 
                        // Underflow?
                        } else if ( x['e'] < Decimal['minE'] ) {
 
                            // Zero.
                            x['c'] = [ x['e'] = 0 ];
                        }
                    }
                } else {
 
                    // Zero.
                    x['c'] = [ x['e'] = 0 ];
                }
                id = 0;
 
                return x;
            };
        })();
 
 
        /*
         * Return a new Decimal whose value is x raised to the power y.
         *
         * x {number|string|Decimal} The base.
         * y {number|string|Decimal} The exponent.
         *
         */
        function pow( x, y ) { return new this(x)['pow'](y); }
 
 
        /*
         * Returns a new Decimal with a random value equal to or greater than 0 and less than 1, and
         * with dp, or Decimal.precision if dp is omitted, decimal places (or less if trailing
         * zeros are produced).
         *
         * [dp] {number} Decimal places. Integer, 0 to MAX_DIGITS inclusive.
         *
         */
        function random(dp) {
            var a, n, v,
                i = 0,
                r = [],
                Decimal = this,
                rand = new Decimal( Decimal['ONE'] );
 
            if ( dp == null || !checkArg( rand, dp, 'random' ) ) {
                dp = Decimal['precision'];
            } else {
                dp |= 0;
            }
 
            n = Math.ceil( dp / LOGBASE );
 
            Iif ( Decimal['crypto'] ) {
 
                // Browsers supporting crypto.getRandomValues.
                if ( crypto && crypto['getRandomValues'] ) {
 
                    a = crypto['getRandomValues']( new Uint32Array(n) );
 
                    for ( ; i < n; ) {
                        v = a[i];
 
                        // 0 >= v < 4294967296
                        // Probability that v >= 4.29e9, is 4967296 / 4294967296 = 0.00116 (1 in 865).
                        if ( v >= 4.29e9 ) {
 
                            a[i] = crypto['getRandomValues']( new Uint32Array(1) )[0];
                        } else {
 
                            // 0 <= v <= 4289999999
                            // 0 <= ( v % 1e7 ) <= 9999999
                            r[i++] = v % 1e7;
                        }
                    }
 
                // Node.js supporting crypto.randomBytes.
                } else if ( crypto && crypto['randomBytes'] ) {
 
                    // buffer
                    a = crypto['randomBytes']( n *= 4 );
 
                    for ( ; i < n; ) {
 
                        // 0 <= v < 2147483648
                        v = a[i] + ( a[i + 1] << 8 ) + ( a[i + 2] << 16 ) +
                            ( ( a[i + 3] & 0x7f ) << 24 );
 
                        // Probability that v >= 2.14e9, is 7483648 / 2147483648 = 0.0035 (1 in 286).
                        if ( v >= 2.14e9 ) {
                            crypto['randomBytes'](4).copy( a, i );
                        } else {
 
                            // 0 <= v <= 4289999999
                            // 0 <= ( v % 1e7 ) <= 9999999
                            r.push( v % 1e7 );
                            i += 4;
                        }
                    }
                    i = n / 4;
 
                } else {
                    ifExceptionsThrow( Decimal, 'crypto unavailable', crypto, 'random' );
                }
            }
 
            // Use Math.random: either Decimal.crypto is false or crypto is unavailable and errors is false.
            Eif (!i) {
 
                for ( ; i < n; ) {
                    r[i++] = Math.random() * 1e7 | 0;
                }
            }
 
            n = r[--i];
            dp %= LOGBASE;
 
            // Convert trailing digits to zeros according to dp.
            if ( n && dp ) {
                v = mathpow( 10, LOGBASE - dp );
                r[i] = ( n / v | 0 ) * v;
            }
 
            // Remove trailing elements which are zero.
            for ( ; r[i] === 0; i-- ) {
                r.pop();
            }
 
            // Zero?
            if ( i < 0 ) {
                r = [ n = 0 ];
            } else {
                n = -1;
 
                // Remove leading elements which are zero and adjust exponent accordingly.
                for ( ; r[0] === 0; ) {
                    r.shift();
                    n -= LOGBASE;
                }
 
                // Count the digits of the first element of r to determine leading zeros.
                for ( i = 1, v = r[0]; v >= 10; ) {
                    v /= 10;
                    i++;
                }
 
                // Adjust the exponent for leading zeros of the first element of r.
                if ( i < LOGBASE ) {
                    n -= LOGBASE - i;
                }
            }
 
            rand['e'] = n;
            rand['c'] = r;
 
            return rand;
        }
 
 
        /*
         * Return a new Decimal whose value is n round to an integer using rounding mode rounding.
         *
         * To emulate Math.round, set rounding to 7 (ROUND_HALF_CEIL).
         *
         * n {number|string|Decimal}
         *
        function round(n) {
            var x = new this(n);
 
            return rnd( x, x['e'] + 1, this['rounding'] );
        }
         */
 
 
        /*
         * Return a new Decimal whose value is the sine of n.
         *
         * n {number|string|Decimal} A number given in radians.
         *
        function sin(n) { return new this( Math.sin(n) + '' ) }
         */
 
 
        /*
         * Return a new Decimal whose value is the square root of n.
         *
         * n {number|string|Decimal}
         *
         */
        function sqrt(n) { return new this(n)['sqrt'](); }
 
 
        /*
         * Return a new Decimal whose value is the tangent of n.
         *
         * n {number|string|Decimal} A number given in radians.
         *
        function tan(n) { return new this( Math.tan(n) + '' ) }
         */
 
 
        /*
         * Return a new Decimal whose value is n truncated to an integer.
         *
         * n {number|string|Decimal}
         *
        function trunc(n) { return new this(n)['trunc']() }
         */
 
 
        /*
         * Create and return a Decimal constructor.
         *
         */
        function decimalFactory(obj) {
 
            /*
             * The Decimal constructor and exported function.
             * Create and return a new instance of a Decimal object.
             *
             * n {number|string|Decimal} A numeric value.
             * [b] {number} The base of n. Integer, 2 to 64 inclusive.
             *
             */
            function Decimal( n, b ) {
                var x = this;
 
                // Constructor called without new.
                Iif ( !( x instanceof Decimal ) ) {
                    ifExceptionsThrow( Decimal, 'Decimal called without new', n );
 
                    return new Decimal( n, b );
                }
 
                // Retain a reference to this Decimal constructor, and shadow
                // Decimal.prototype.constructor which points to Object.
                x['constructor'] = Decimal;
 
                // Duplicate.
                if ( n instanceof Decimal ) {
 
                    if ( b == null ) {
                        id = 0;
                        x['s'] = n['s'];
                        x['e'] = n['e'];
                        x['c'] = ( n = n['c'] ) ? n.slice() : n;
 
                        return x;
                    } else if ( b == 10 ) {
 
                        return rnd( new Decimal(n), Decimal['precision'], Decimal['rounding'] );
                    } else {
                        n += '';
                    }
                }
 
                return parseDecimal( Decimal, x, n, b );
            }
 
 
            /* ************************ CONSTRUCTOR DEFAULT PROPERTIES ************************** */
 
            /*
             These default values must be integers within the stated ranges (inclusive).
             Most of these values can be changed during run-time using Decimal.config.
             */
 
            /*
             The maximum number of significant digits of the result of a calculation or base
             conversion.
             E.g.  Decimal.config({ precision: 20 })
             */
            Decimal['precision'] = 20;                        // 1 to MAX_DIGITS
 
            /*
             The rounding mode used when rounding to precision.
 
             ROUND_UP         0 Away from zero.
             ROUND_DOWN       1 Towards zero.
             ROUND_CEIL       2 Towards +Infinity.
             ROUND_FLOOR      3 Towards -Infinity.
             ROUND_HALF_UP    4 Towards nearest neighbour. If equidistant, up.
             ROUND_HALF_DOWN  5 Towards nearest neighbour. If equidistant, down.
             ROUND_HALF_EVEN  6 Towards nearest neighbour. If equidistant, towards even neighbour.
             ROUND_HALF_CEIL  7 Towards nearest neighbour. If equidistant, towards +Infinity.
             ROUND_HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
 
             E.g.
             Decimal.rounding = 4;
             Decimal.rounding = Decimal.ROUND_HALF_UP;
             */
            Decimal['rounding'] = 4;                          // 0 to 8
 
            /*
             The modulo mode used when calculating the modulus: a mod n.
             The quotient (q = a / n) is calculated according to the corresponding rounding mode.
             The remainder (r) is calculated as: r = a - n * q.
 
             UP         0 The remainder is positive if the dividend is negative, else is negative.
             DOWN       1 The remainder has the same sign as the dividend.
                          This modulo mode is commonly known as "truncated division" and matches
                          as closely as possible, the behaviour of JS remainder operator (a % n).
             FLOOR      3 The remainder has the same sign as the divisor (Python %).
             HALF_EVEN  6 This modulo mode implements the IEEE 754 remainder function.
             EUCLID     9 Euclidian division. q = sign(n) * floor(a / abs(n)).
                          The remainder is always positive.
 
             The above modes - truncated division, floored division, Euclidian division and IEEE 754
             remainder - are commonly used for the modulus operation. Although any other of the
             rounding modes can be used, they may not give useful results.
             */
            Decimal['modulo'] = 1;                            // 0 to 9
 
            // The exponent value at and beneath which toString returns exponential notation.
            // Number type: -7
            Decimal['toExpNeg'] = -7;                         // 0 to -EXP_LIMIT
 
            // The exponent value at and above which toString returns exponential notation.
            // Number type: 21
            Decimal['toExpPos'] = 21;                         // 0 to EXP_LIMIT
 
            // The minimum exponent value, beneath which underflow to zero occurs.
            // Number type: -324  (5e-324)
            Decimal['minE'] = -EXP_LIMIT;                     // -1 to -EXP_LIMIT
 
            // The maximum exponent value, above which overflow to Infinity occurs.
            // Number type:  308  (1.7976931348623157e+308)
            Decimal['maxE'] = EXP_LIMIT;                      // 1 to EXP_LIMIT
 
            // Whether Decimal Errors are ever thrown.
            Decimal['errors'] = true;                         // true/false
 
            // Whether to use cryptographically-secure random number generation, if available.
            Decimal['crypto'] = false;                        // true/false
 
            // Format specification for the Decimal.prototype.toFormat method
            Decimal.format = {
                decimalSeparator: '.',
                groupSeparator: ',',
                groupSize: 3,
                secondaryGroupSize: 0,
                fractionGroupSeparator: '\xA0',              // non-breaking space
                fractionGroupSize: 0
            };
 
 
            /* ********************** END OF CONSTRUCTOR DEFAULT PROPERTIES ********************* */
 
 
            Decimal.prototype = P;
 
            Decimal['ONE'] = new Decimal(1);
 
            /*
            // Pi to 80 s.d.
            Decimal['PI'] = new Decimal(
                '3.1415926535897932384626433832795028841971693993751058209749445923078164062862089'
            );
             */
 
            Decimal['ROUND_UP'] = 0;
            Decimal['ROUND_DOWN'] = 1;
            Decimal['ROUND_CEIL'] = 2;
            Decimal['ROUND_FLOOR'] = 3;
            Decimal['ROUND_HALF_UP'] = 4;
            Decimal['ROUND_HALF_DOWN'] = 5;
            Decimal['ROUND_HALF_EVEN'] = 6;
            Decimal['ROUND_HALF_CEIL'] = 7;
            Decimal['ROUND_HALF_FLOOR'] = 8;
 
            // modulo mode
            Decimal['EUCLID'] = 9;
 
            //Decimal['abs'] = abs;
            //Decimal['acos'] = acos;
            //Decimal['asin'] = asin;
            //Decimal['atan'] = atan;
            //Decimal['atan2'] = atan2;
            //Decimal['ceil'] = ceil;
            //Decimal['cos'] = cos;
            //Decimal['floor'] = floor;
            //Decimal['round'] = round;
            //Decimal['sin'] = sin;
            //Decimal['tan'] = tan;
            //Decimal['trunc'] = trunc;
 
            Decimal['config'] = config;
            Decimal['constructor'] = decimalFactory;
            Decimal['exp'] = exp;
            Decimal['ln'] = ln;
            Decimal['log'] = log;
            Decimal['max'] = max;
            Decimal['min'] = min;
            Decimal['pow'] = pow;
            Decimal['sqrt'] = sqrt;
            Decimal['random'] = random;
 
            if ( obj != null ) {
                Decimal['config'](obj);
            }
 
            return Decimal;
        }
 
        return decimalFactory();
    })();
 
 
    // Export.
 
 
    // AMD.
    Iif ( typeof define == 'function' && define.amd ) {
 
        define(function () {
            return decimal;
        });
 
    // Node and other environments that support module.exports.
    } else Eif ( typeof module != 'undefined' && module.exports ) {
        module.exports = decimal;
 
        Eif ( !crypto ) {
 
            try {
                crypto = require('crypto');
            } catch (e) {}
        }
 
    // Browser.
    } else {
        noConflict = global['Decimal'];
 
        decimal['noConflict'] = function () {
            global['Decimal'] = noConflict;
 
            return decimal;
        };
 
        global['Decimal'] = decimal;
    }
})(this);