Omirion Posted March 12, 2010 Share Posted March 12, 2010 function test(myTrig,t){ var num = arguments.length if (num == 0){ alert("preset stage"); setTimeout(function(){test(1,1)},2); } if (myTrig == 1){ alert("starting first recursion"); if (t==1.5 || t>1.5) { alert("exiting"); return ; } alert(myTrig); alert(t); t += 0.1; setTimeout(function(){test(1,t)},2); } if (myTrig == 2){ alert(myTrig); } } When this function is run clean like so test(); It passes trough a preset stage and then is passed on to the first recursive part of the code. if (myTrig == 1){ alert("starting first recursion"); if (t==1.5 || t>1.5) { alert("exiting"); return ; } alert(myTrig); alert(t); t += 0.1; setTimeout(function(){test(1,t)},2); Each time var t is incremented by 0.1. But not exactly, a 0.000000001 value is also added. Any JS magician care to explain? Link to comment https://forums.phpfreaks.com/topic/194985-js-anomaly/ Share on other sites More sharing options...
Adam Posted March 12, 2010 Share Posted March 12, 2010 http://www.builderau.com.au/program/javascript/soa/Why-I-Love-ECMAScript-4-Real-Decimals/0,339028434,339289678,00.htm Link to comment https://forums.phpfreaks.com/topic/194985-js-anomaly/#findComment-1025116 Share on other sites More sharing options...
Omirion Posted March 12, 2010 Author Share Posted March 12, 2010 An interesting read thanks. Link to comment https://forums.phpfreaks.com/topic/194985-js-anomaly/#findComment-1025143 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.