JSFiddle - React, Tailwind, and code Playground
by ronilan
JavaScript
// SQRT without Math
// general settings
var start = 0;
var end = 10000;
var accuracy = 0.0000000000001;
function sqrt(solve) {
var result = 0;
var go = true;
while (go) {
if (result * result < solve) {
start = result;
} else {
end = result;
}
result = start + (end - start) / 2;
// stop condition
if (Math.abs(result * result - solve) < accuracy) {
go = false;
}
}
return result;
}
console.log(sqrt(5.345), Math.sqrt(5.345));