title: How many times can I multiple a number by a decimal/fraction before it reaches close to zero
body: <p>I'm trying to determine how far ahead to check for a ledge based on an objects speed. This way the object can stop accelerating and let friction stop it.</p>
  
  <p><a href="https://i.stack.imgur.com/1FU7W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1FU7W.png" alt="enter image description here"></a></p>
  
  <p><strong>the problem</strong></p>
  
  <p>friction is 0.9 * horizontalSpeed each step.</p>
  
  <p>when horizontalSpeed is less than 0.001 we set the horizontalSpeed to 0</p>
  
  <p>how long it takes to reach 0.001 is horizontalSpeed = 1</p>
  
  <p><strong>how im currently solving</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var horizontalSpeed = 1    
  var friction = 0.9
  var closeEnoughToZero = 0.001
  var distance = 0
  
  while(horizontalSpeed &gt; closeEnoughToZero) {
      horizontalSpeed *= friction
      distance += horizontalSpeed
  }
  
  console.log(distance) // 8.99</code></pre>
  </div>
  </div>
  </p>
  
  <p>Possible already the solution I just feel it is a bit brute force and likely some type of math function that is handy for this!</p>