Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

increment float32 by smallest possible amount (using numpy currently)

Tags:

python

numpy

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?

like image 618
Austin Avatar asked Sep 14 '15 22:09

Austin


People also ask

Is Python float 32 or 64?

Python's floating-point numbers are usually 64-bit floating-point numbers, nearly equivalent to np.

Is float32 the same as float?

float is one of the available numeric data types in Go used to store decimal numbers. float32 is a version of float that stores decimal values composed of 32 bits of data.

How do I find my next floating-point number?

To return the next floating-point value after a value towards another value, element-wise, use the numpy. nextafter() method.


1 Answers

Seems to work fine:

>>> x = np.float32(1.)
>>> y = np.nextafter(x, np.float32(2.))
>>> y
1.0000001
>>> type(y)
numpy.float32
like image 85
wim Avatar answered Nov 14 '22 23:11

wim