Austin
Austin

Reputation: 75

increment float32 by smallest possible amount (using numpy currently)

Trying to increment a single-precision floating point number by the smallest possible amount. I see there is a nextafter function, but I can't get that to work for single precision numbers. Any suggestions?

Upvotes: 5

Views: 722

Answers (1)

wim
wim

Reputation: 362587

Seems to work fine:

>>> x = np.float32(1.)
>>> y = np.nextafter(x, np.float32(2.))
>>> y
1.0000001
>>> type(y)
numpy.float32

Upvotes: 10

Related Questions