numpy.float128 的内部精度是多少? [英] What is the internal precision of numpy.float128?

查看:27
本文介绍了numpy.float128 的内部精度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

numpy.float128 内部映射到什么精度?是 __float128 还是 long double?或者完全是别的什么?

What precision does numpy.float128 map to internally? Is it __float128 or long double? Or something else entirely?

如果有人知道的话,一个潜在的后续问题:在 C 中将 __float128 转换为(16 字节)长双精度值是否安全?(这是为了与对长双精度进行操作的 C 库接口).

A potential follow on question if anybody knows: is it safe in C to cast a __float128 to a (16 byte) long double, with just a loss in precision? (this is for interfacing with a C lib that operates on long doubles).

响应评论,平台是Linux-3.0.0-14-generic-x86_64-with-Ubuntu-11.10-oneiric".现在,如果 numpy.float128 具有取决于平台的不同精度,那对我来说也是有用的知识!

In response to the comment, the platform is 'Linux-3.0.0-14-generic-x86_64-with-Ubuntu-11.10-oneiric'. Now, if numpy.float128 has varying precision dependent on the platform, that is also useful knowledge for me!

明确地说,我感兴趣的是精度,而不是元素的大小.

Just to be clear, it is the precision I am interested in, not the size of an element.

推荐答案

非常推荐使用 longdouble 而不是 float128,因为它非常一团糟,ATM.Python 会在初始化期间将其强制转换为 float64.

It's quite recommended to use longdouble instead of float128, since it's quite a mess, ATM. Python will cast it to float64 during initialization.

在 numpy 中,它可以是 double 或 long double.它定义在 npy_common.h 并取决于您的平台.我不知道您是否可以将其直接包含在源代码中.

Inside numpy, it can be a double or a long double. It's defined in npy_common.h and depends of your platform. I don't know if you can include it out-of-the-box into your source code.

如果您在算法的这部分不需要性能,更安全的方法可能是将其导出为字符串并使用 strold 之后.

If you don't need performance in this part of your algorithm, a safer way could be to export it to a string and use strold afterwards.

这篇关于numpy.float128 的内部精度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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