Using long doubles in windows

I have an application in which I absolutely must use the long double data type due to a catastrophic truncation error when doing math with double precision. My testing routines are crazy because on Windows long double with Visual Studio, the alias is simply doubled, and on Linux and OSX the long double is a real long double with a nominal accuracy of 1e-19.

In mingw (windows gcc port) i am confused. Mingw claims that LDBL_EPSILON has an accuracy of 1e-19, but googleing assumes that mingw uses c runtime, which is actually only microsoft c runtime, which does not support real long doubles. Can anyone shed some light here?

EDIT . The essence of the problem is this: in mingw, if I call the math function log(long double x) , is it just an alias of log(double x) ? In any case, how can I write my own script to test this behavior and / or test it?

+5
source share
2 answers

Following code

 #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; } 

produced 16 1.41421 output, so good

Drop the preprocessor (option -E) and find out that the internal but different from the double sqrt () function was called

 using ::sqrt; inline constexpr float sqrt(float __x) { return __builtin_sqrtf(__x); } inline constexpr long double sqrt(long double __x) { return __builtin_sqrtl(__x); } 

Same for log (), sin (), you name it

So, I believe that MinGW supports a long double format in arithmetic as well as in math.functions, and this support is built in, not libquadmath based

+3
source

Just tried with MinGW (MinGW distribution by nuwen, gcc / g ++ 4.9.1, 64bit)

Next program

 #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; } 

produced 8 16

I would suggest that a long double is supported and different from a standard double, so your calculations can give the desired result

I heard that there are problems with long print doubling in Windows due to using the old version of MS. You may need to use throws or roll your own output routines.

+1
source

Source: https://habr.com/ru/post/1207959/


All Articles