最小正float64数 [英] Smallest positive float64 number

查看:228
本文介绍了最小正float64数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一个尽可能接近零的numpy.float64值.

I need to find a numpy.float64 value that is as close to zero as possible.

Numpy提供了几个常数,它们可以执行类似的操作:

Numpy offers several constants that allow to do something similar:

  • np.finfo(np.float64).eps = 2.2204460492503131e-16
  • np.finfo(np.float64).tiny = 2.2250738585072014e-308
  • np.finfo(np.float64).eps = 2.2204460492503131e-16
  • np.finfo(np.float64).tiny = 2.2250738585072014e-308

它们都相当小,但是当我这样做时

These are both reasonably small, but when I do this

>>> x = np.finfo(np.float64).tiny
>>> x / 2
6.9533558078350043e-310

结果甚至更小.当使用即兴二进制搜索时,在将值四舍五入为0.0之前,我可以降低到大约1e-323.

the result is even smaller. When using an impromptu binary search I can get down to about 1e-323, before the value is rounded down to 0.0.

我在numpy中是否缺少此常量?或者,是否有 right 方法来做到这一点?

Is there a constant for this in numpy that I am missing? Alternatively, is there a right way to do this?

推荐答案

使用np.nextafter.

>>> import numpy as np
>>> np.nextafter(0, 1)
4.9406564584124654e-324
>>> np.nextafter(np.float32(0), np.float32(1))
1.4012985e-45

这篇关于最小正float64数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆