在64位体系结构上不能在Python中使用128位浮点

2024-04-27 14:29:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我检查了python终端中指针的大小(在热情的Canopy IDE中) 通过

import ctypes
print (ctypes.sizeof(ctypes.c_voidp) * 8)

我有一个64位的体系结构,使用numpy.float64很好。但我不能用np.float128

np.array([1,1,1],dtype=np.float128)

或者

np.float128(1)

结果:

AttributeError: 'module' object has no attribute 'float128'

我正在运行以下版本:

sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)

Tags: importnumpy终端体系结构npctypesideprint
1条回答
网友
1楼 · 发布于 2024-04-27 14:29:33

更新:从评论来看,在64位系统上使用128位浮点似乎毫无意义。

我在64位的Ubuntu 14.04系统上使用anacondasys.version_info(major=2, minor=7, micro=9, releaselevel='final', serial=0)

128位浮点运算很好:

import numpy
a = numpy.float128(3)

这可能是一个分发问题。尝试:

编辑: 从评论中更新:

Not my downvote, but this post doesn't really answer the "why doesn't np.float128 exist on my machine" implied question. The true answer is that this is platform specific: float128 exists on some platforms but not others, and on those platforms where it does exist it's almost certainly simply the 80-bit x87 extended precision type, padded to 128 bits. – Mark Dickinson

相关问题 更多 >