programming-examples/python/Math/Create a range for floating numbers.py
2019-11-15 12:59:38 +01:00

14 lines
465 B
Python

#https://gist.github.com/axelpale/3e780ebdde4d99cbb69ffe8b1eada92c
def frange(x, y, jump=1.0):
i = 0.0
x = float(x) # Prevent yielding integers.
y = float(y) # Comparison converts y to float every time otherwise.
x0 = x
epsilon = jump / 2.0
yield x # yield always first value
while x + epsilon < y:
i += 1.0
x = x0 + i * jump
yield x
print(list(frange(0.0, 1.0, 0.1)))