# Example NumPy Floats

**URL:** <https://discuss.python.org/t/example-numpy-floats/23952>\
**Category:** Python Help\
**Tags:** help\
**Created:** [February 16, 2023, 5:00pm UTC](https://discuss.python.org/t/example-numpy-floats/23952 "2023-02-16T17:00:23Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![franklinvp](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/franklinvp/32/11142_2.png) [@franklinvp](https://discuss.python.org/u/franklinvp)\
**Post date:** [February 16, 2023, 9:03pm UTC](https://discuss.python.org/t/example-numpy-floats/23952/4 "2023-02-16T21:03:45Z")

</div>

You can add `0.5` to `0.0` while the result has not become larger than `15`.  
A first attempt can be

```auto
result = []
first = 0.0
last = 15.0
increment = 0.5
while current_value <= last:
  result.append(current_value)
  current_value += increment

```

Since we can predict how many values we will get, namely `int((15 - 0.0) / 0.5) + 1` we could also do

```auto
first = 0.0
last = 15.0
increment = 0.5
result = [first + n * increment for n in range(int((last - first)/increment) + 1)]

```

Note that `0.5` =2^{-1} and `0.0` are sums of powers of 2. So, all the values that we need are values that float can take. If they had given other value instead of `0.5` perhaps the values that we need are not values that `float` can take. So, we have to compute them approximatively. The first approach of doing `current_value += increment` can magnify the error in that case. So, it might be better to use the `first + n * increment` approach.

---

_[View the full topic](https://discuss.python.org/t/example-numpy-floats/23952)._
