| 743 | return this.polynomial(...out) |
| 744 | } |
| 745 | numeralSolve(f, end, from = -100, to = 100, step = 0.1) { |
| 746 | let buffer = [] |
| 747 | let index = [] |
| 748 | for (let i = new BigNumber(from); i.lt(to); i = i.plus(step)) { |
| 749 | buffer.push(this.run(f, i.toNumber())) |
| 750 | index.push(i.toNumber()) |
| 751 | } |
| 752 | function closest(num, arr) { |
| 753 | let curr = arr[0]; |
| 754 | let diff = Math.abs(num - curr); |
| 755 | for (let val = 0; val < arr.length; val++) { |
| 756 | const newdiff = Math.abs(num - arr[val]); |
| 757 | if (newdiff < diff) { |
| 758 | diff = newdiff; |
| 759 | curr = arr[val]; |
| 760 | } |
| 761 | } |
| 762 | return curr; |
| 763 | } |
| 764 | const close = closest(end, buffer.filter(x => !isNaN(x))) |
| 765 | return index[buffer.indexOf(close)] |
| 766 | } |
| 767 | polynomial() { |
| 768 | const arg = [...arguments] |
| 769 | const args = this.reverse(arg) |