为什么微软放弃长双精度数据类型?
不久前,我编写了一个使用一些阶乘函数的程序。我使用长双精度数据类型来支持“相对”大数字。
现在,我从 codeblocks 更改为 Visualstudio 2010,我想知道为什么我的程序不再工作,直到经过一些研究后我意识到 MS 已经放弃了 long double 数据类型。 这有什么特殊原因吗?对我来说,这看起来就像是技术上的倒退。
有什么替代方案可以使用吗? (我也很乐意使用 boost 库中的替代方案)。
A while ago I wrote a program which used some factorial functions. I used the long double data type to support "relative" big numbers.
Now, I changed from codeblocks to Visualstudio 2010, I was wondering why my program didn't work any more till I realized after some research that MS has abandonded the long double data type.
Is there any special reason for this? To me it looks very like step backwards in terms of technology.
Is there any alternative to use? (I would also be happy with an alternative out of the boost library).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定为什么您认为
long double
被“放弃”,因为它是 C++ 标准的一部分,因此兼容的实现必须实现它。他们所做的“放弃”是
long double
数学函数的重载,他们这样做是因为:反过来,旧 VS 版本中的
long double
为 80 位,是因为:尽管如此,他们选择不支持这些重载,即使使用相同大小的 double 和 long double 类型(两者都可以做成 64 位),这是一个耻辱,因为它们也是 C++ 标准的一部分。但是,这就是适合您的 Microsoft。专心固执。
然而,尽管这些重载在 Visual Studio 中基本上已被弃用,但它们仍然可用,因此您仍然应该能够使用它们:
在我看来,您一直依赖
long double
来支持特定范围的数值,因此当它在不同的工具链中发生变化时,会遇到回归问题。如果您有特定的数字范围要求,请使用固定范围整数类型。这里有几个选项:
stdint.h
- 一些 C++ 工具链支持作为扩展的 C99 功能;stdint.h
- Boost 作为库重新实现的 C99 功能;cstdint
- 如果您正在编写 C++0x 代码,则可能会用到 C++0x 功能。I'm not sure why you think that
long double
was "abandoned", as it is part of the C++ Standard and therefore a compliant implementation must, well, implement it.What they did "abandon" is
long double
overloads of mathematical functions, and they did this because:which, in turn, along with
long double
in older VS versions being 80-bit, is because:Still, that they chose not to support these overloads, even with same-sized
double
andlong double
types (both could have been made 64-bit), is a shame because they are also part of the C++ Standard. But, well, that's Microsoft for you. Intently stubborn.However, although these overloads are essentially deprecated in Visual Studio, they are still available, so you should still be able to use them:
It sounds to me like you have been relying on
long double
to support a specific range of numeric values, and have consequently run into regression issues when that has changed in a different toolchain.If you have a specific numeric range requirement, use fixed-range integral types. Here you have a few options:
stdint.h
- a C99 feature that some C++ toolchains support as an extension;stdint.h
- a C99 feature that Boost re-implements as a library;cstdint
- a C++0x feature that may be of use if you are writing C++0x code.