title: How to prevent float imprecision from affecting numpy.arange?
body: <p>Because <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.arange.html" rel="nofollow noreferrer">numpy.arange()</a> uses <code>ceil((stop - start)/step)</code> to determine the number of items, a small float imprecision <code>(stop = .400000001)</code> can add an unintended value to the list.</p>
  <h2>Example</h2>
  <p>The first case does not include the stop point <strong>(intended)</strong></p>
  <pre><code>&gt;&gt;&gt; print(np.arange(.1,.3,.1))
  [0.1 0.2]
  </code></pre>
  <p>The second case includes the stop point <strong>(not intended)</strong></p>
  <pre><code>&gt;&gt;&gt; print(np.arange(.1,.4,.1))
  [0.1 0.2 0.3 0.4]
  </code></pre>
  <p><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html" rel="nofollow noreferrer">numpy.linspace()</a> fixes this problem, <code>np.linspace(.1,.4-.1,3)</code>. but requires you know the number of steps. <code>np.linspace(start,stop-step,np.ceil((stop-step)/step))</code> leads to the same incosistencies.</p>
  <h2>Question</h2>
  <p>How can I generate a reliable <code>float</code> range without knowing the # of elements in the range?</p>
  <h2>Extreme Case</h2>
  <p>Consider the case  in which I want generate a float index of unknown precision</p>
  <pre><code>np.arange(2.00(...)001,2.00(...)021,.00(...)001)
  </code></pre>