I have been using Decimal.js to increase the precision of my function that calculates the mth positive root of a = tan(a)
through trial and error. It works, however it returns a "Precision limit exceeded" error for nTan(504)
(would return 4.4934... to 505 digits) and greater.
var Decimal = require("decimal.js");
var fs = require("fs");
function nTan (acc, m) {
var test = [1], acc = (parseInt(acc) || 15) + 1;
Decimal.set({precision: acc});
var n = new Decimal(fs.readFileSync("result.txt", "utf-8") || 4.4).toString();
while (n.length + test.length - 2 < acc) {
var dec = (new Decimal(n + test.join("")));
if (dec.tan().cmp(n + test.join("")) >= 0) {
test[test.length - 1]--;
test.push(1);
} else test[test.length - 1]++;
if (test[test.length - 1] == 10) { test[test.length - 1] = 9; test.push(1); }
}
return (new Decimal(n + test.slice(0, -1).join(""))).plus(Math.PI * (parseInt(m) || 0)).toString();
}
My question(s) are:
- Why won't Decimal.js calculate past 504 digits when it advertises the capacity for up to and including 1e+9 digits?
- Is there an alternative node or JS API that would support this program to a greater precision?