Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using long doubles on windows

Tags:

c++

windows

mingw

I have an application where I absolutely must use long double data type due to catastrophic truncation error when doing math with double precision. My testing procedures are going crazy because on windows long double with Visual Studio is just an alias to double, while on linux and OSX, long double is a real long double with nominally precision of 1e-19.

On mingw (windows port of GCC) is where I am confused. Mingw claims that LDBL_EPSILON has a precision of 1e-19, but googleing suggests that the mingw uses the c runtime that is actually just the microsoft c runtime which doesn't support real long doubles. Can anyone shed any light here?

EDIT: The crux of the problem is this: on mingw, if I call the math function log(long double x), is this just an alias to log(double x)? In either case, how could I write my own script to test this behavior and/or test for it?

like image 623
ibell Avatar asked Sep 30 '22 07:09

ibell


1 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 output 16 1.41421, so far so good

Ran it throw preprocessor (-E option) and found out that internal, but different from double sqrt() function were 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

Thus, I believe MinGW support long double format in arithmetics as well as in math.functions, and this support is built-in, not libquadmath based

like image 198
Severin Pappadeux Avatar answered Oct 04 '22 03:10

Severin Pappadeux