javascript - Get number of times a number will multiply itself with another until reach a certain limit -


i can number of times number multiply until reach limit:

var velocity = -5.706875; var friction = 0.9925; var limit = 0 var times = 0;  while (math.floor(math.abs(velocity)*10) > limit) {     velocity *= friction;     times += 1; } // times = 538 

is there way times without loop? tried math.log(5.706875, 0.9925) gives result.

sure, there are:

times = math.ceil(math.log(-0.1/velocity)/math.log(friction)); 

edit:

actually, taking account limit var, be:

times = math.ceil(math.log(-(0.1+limit/10)/velocity)/math.log(friction)); 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

java - Could not locate OpenAL library -

Non Unique Username with ASP.Net Identity 2.0 -