尝试以尽可能小的数量递增单精度浮点数.我看到有一个nextafter函数,但我不能让它用于单精度数字.有什么建议?
我正在开展一个学校项目,要求我对单精度浮点数做一些数学计算.我以为我会在numpy中使用float32格式,因为python实际上是我所知道的唯一通用语言.IMO这个数字格式应该能够处理数字1.0000001,但它一直将我的答案截断为1.0.我能得到的最接近的是1.00001.任何人都可以对此有所了解吗?我是这个浮点格式和Python的新手.
import numpy as np
keyInput=np.float32(input("Enter a number and i'll float 32 it: "))
print(keyInput)
print(np.float32(keyInput))
print("This is of type: ",type(keyInput))
input('Press ENTER to exit')
Run Code Online (Sandbox Code Playgroud)