From 778e2d7a96e9e393aa18db60aa71cd2c9f84bff4 Mon Sep 17 00:00:00 2001 From: Eric Douglas Date: Sat, 7 Jun 2014 19:21:41 -0300 Subject: [PATCH] add lec04.js 01.01.04 readme --- .../lec04.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/04-machine-interpretation-of-program/lec04.js diff --git a/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/04-machine-interpretation-of-program/lec04.js b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/04-machine-interpretation-of-program/lec04.js new file mode 100644 index 0000000..f809c15 --- /dev/null +++ b/archives/01-introduction-to-computer-science-and-programming/archives/UNIT-01/04-machine-interpretation-of-program/lec04.js @@ -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 );