MCPcopy Create free account
hub / github.com/arguiot/TheoremJS / numeralSolve

Method numeralSolve

__test__/theorem.js:745–766  ·  view source on GitHub ↗
(f, end, from = -100, to = 100, step = 0.1)

Source from the content-addressed store, hash-verified

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)

Callers 3

findRootsMethod · 0.95
findRoots.jsFile · 0.80
test.jsFile · 0.80

Calls 3

runMethod · 0.95
closestFunction · 0.85
plusMethod · 0.80

Tested by

no test coverage detected