mirror of
https://github.com/ossu/computer-science.git
synced 2024-12-27 08:19:35 -05:00
add lec04.js 01.01.04 readme
This commit is contained in:
parent
cc0defed0f
commit
778e2d7a96
@ -0,0 +1,16 @@
|
||||
var x = 0.5;
|
||||
var epsilon = 0.01;
|
||||
var low = 0;
|
||||
var high = x;
|
||||
var ans = ( high + low ) / 2;
|
||||
|
||||
while ( Math.abs( Math.pow( ans, 2 ) ) >= epsilon && ans <= x ) {
|
||||
console.log( 'ans = ' + ans + ' low = ' + low + ' high = ' + high );
|
||||
|
||||
if ( Math.pow( ans, 2 ) < x )
|
||||
low = ans;
|
||||
else
|
||||
high = ans;
|
||||
}
|
||||
|
||||
console.log( ans + ' is close to square root of ' + x );
|
Loading…
Reference in New Issue
Block a user