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
Post a Comment