有没有开源的c/c++ IEEE-754 操作的实现?

发布于 2024-08-20 00:36:40 字数 1539 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青巷忧颜 2024-08-27 00:36:40

我相信 C 库 SoftFloatfdlibm 适合您正在寻找的内容。其他包括 Linux(GNU libc、glibc)或 *BSD libc 的 数学函数。最后,CRlibm 您应该也会感兴趣。

Ulrich Drepper 有一篇有趣的查看不同的数学库,可能也值得一读。

I believe the C libraries SoftFloat and fdlibm are suitable for what you are looking for. Others include Linux (GNU libc, glibc) or *BSD libc's math functions. Finally, CRlibm should also be of interest to you.

Ulrich Drepper has a interesting look at different math libraries, that might be also worth reading through.

压抑⊿情绪 2024-08-27 00:36:40

我一定让你失望了:几乎没有。

虽然从技术上讲存在 IEEE-754 兼容系统,因为它们确实
不实现标准中描述的非必需功能,参考
允许

  • 访问所有舍入模式的
  • 实现支持信号 NaN
  • 支持捕获所有五个陷阱,这

在标准语言中并不存在。这会导致反复出现的麻烦
威廉·卡汉 (William Kahan),该标准及其改编背后的主要力量
在英特尔处理器上。

我不知道是否有一些深奥的语言确实支持它们,
但我可以排除 Java、C#、C++、Fortran。

编辑:虽然缺乏编译器支持,但我建议 Hausers SoftFloat
mctylr 给出的实现。豪瑟知道他在做什么。

http:// Portal.acm.org/itation.cfm?id=227699.227701&coll=portal&dl=ACM&CFID=77938829&CFTOKEN=18578907

I must disappoint you: There is practically none.

While technically there are IEEE-754 compliant systems because they do
not implement non-required features described in the standard, a reference
implementation allowing

  • access to all rounding modes
  • support signalling NaNs
  • support trapping of all five traps

does not exist in the standard languages. This causes recurring woes
of William Kahan, the main force behind the standard and its adaption
on the Intel processors.

I don't know if there are some esoteric languages which do support them,
but I can rule out Java, C#, C++, Fortran.

EDIT: While there is a lack of compiler support, I advise Hausers SoftFloat
implementation given by mctylr. Hauser knows what he is doing.

http://portal.acm.org/citation.cfm?id=227699.227701&coll=portal&dl=ACM&CFID=77938829&CFTOKEN=18578907

娇纵 2024-08-27 00:36:40

一个相当令人困惑的问题;在 C++ 中,假设此类细节由硬件或编译器处理。所以,在 C++ 中,浮点加法是

float a = 1.0;
float b = 2.0;
float c = a + b;

我确信这不是你真正的意思;也许您会受益于此页面,它试图模拟javascript 中的 IEEE-754 兼容硬件?

A rather confusing question; in C++ it is assumed this sort of detail is taken care of by the hardware or the compiler. So, in C++ floating-point addition would be

float a = 1.0;
float b = 2.0;
float c = a + b;

I'm sure this is not what you actually meant; perhaps you'd benefit from this page which tries to emulate IEEE-754-compliant hardware in javascript?

淡水深流 2024-08-27 00:36:40

一种解决办法可以是 python。 python有一个函数可以转换IEEE-754 32/64位精度十六进制浮点

   import struct
   struct.unpack('!f', '41973333'.decode('hex'))[0]

你可以用python编写你的应用程序或者只是创建一个python函数并在C/C++中调用它

我不确定如何从C/调用python C++但这是可能的。 从 C++ 调用 Python 函数

one work around for you could python. python has a function that can convert IEEE-754 32/64 bit precision HEX float point

   import struct
   struct.unpack('!f', '41973333'.decode('hex'))[0]

You can either write you app in python or just create a python function and call it in C/C++

I'm unsure how to call python from C/C++ but it is possible. Calling Python functions from C++

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文