Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在windows上使用长双精度_C++_Windows_Mingw - Fatal编程技术网

C++ 在windows上使用长双精度

C++ 在windows上使用长双精度,c++,windows,mingw,C++,Windows,Mingw,我有一个应用程序,我绝对必须使用长双精度数据类型,因为在使用双精度进行数学运算时会出现灾难性的截断错误。我的测试过程快疯了,因为在使用Visual Studio的windows long double上,long double只是double的别名,而在linux和OSX上,long double是真正的long double,名义精度为1e-19 在mingw(GCC的windows端口)上,我感到困惑。Mingw声称LDBL_EPSILON的精度为1e-19,但Google建议Mingw使用

我有一个应用程序,我绝对必须使用
长双精度
数据类型,因为在使用双精度进行数学运算时会出现灾难性的截断错误。我的测试过程快疯了,因为在使用Visual Studio的windows long double上,long double只是double的别名,而在linux和OSX上,long double是真正的long double,名义精度为1e-19

在mingw(GCC的windows端口)上,我感到困惑。Mingw声称LDBL_EPSILON的精度为1e-19,但Google建议Mingw使用的c运行时实际上只是microsoft c运行时,它不支持真正的长双倍。有人能在这里解释一下吗

EDIT:问题的关键在于:在mingw上,如果我调用数学函数
log(长双x)
,这只是
log(双x)
的别名吗?在这两种情况下,我如何编写自己的脚本来测试这种行为和/或测试它呢?

刚刚使用MinGW(nuwen的MinGW发行版,gcc/g++4.9.1,64位)

后续程序

#include <iostream>

int main(void)
{
    double x = 1.0;
    long double y = 2.0L;

    std::cout << sizeof(x) << std::endl;
    std::cout << sizeof(y) << std::endl;
}
#包括
内部主(空)
{
双x=1.0;
长双y=2.0升;
标准::cout以下代码

#include <iostream>
#include <cmath>

int main(void)
{
    long double y = 2.0L;

    std::cout << sizeof(y) << std::endl;

    long double q = sqrt(y);

    std::cout << q << std::endl;

    return 0;
}
log()和sin()也一样,您可以指定它


因此,我相信MinGW在算术和math.functions中都支持长双格式,这种支持是内置的,而不是基于libquadmath的

基本算术通常是语言的一部分,而不是
C运行时
的一部分,后者主要指C标准库和运行时工具(如sign)的实现al处理、内存分配等。但数学函数不是c运行时的一部分吗?例如,log(long double)?如果我错了,请原谅我的无知一个常见的新手错误是减去两个大致相等的数字。无论如何,先看看算法是个好主意是的,我远非新手,算法已经过大量优化以避免截断,等等。因此->我确实需要长双精度长双精度的打印在mingw中已修复,您只需使用%Lg而不是%g进行常规浮点输出。这是一个好消息,非常感谢。如果在Windows GCC映射中ped“长双”从libquadmath输入到uu float128。我建议检查libquadmath文档,这个库有所有的数学函数和与字符串的转换。刚刚检查了上面提到的MinGW 4.9.1发行版,它确实有libquadmath。安装的quadmath非常慢,而且由于性能也非常重要,我需要长双倍,而不是quadmath。如果我没弄错的话,quad数学是软件仿真的,而长双倍可用于某些SSE库
using ::sqrt;

inline constexpr float sqrt(float __x)
{ return __builtin_sqrtf(__x); }

inline constexpr long double sqrt(long double __x)
{ return __builtin_sqrtl(__x); }