How to determine if long double enhanced precision or not at compile time

On multiple systems, a double value is the same as a long double value. How can I determine if a long double has extended precision than double at compile time and use it for conditional compilation.

I see that in libgcc there are predefined macros SIZEOF_DOUBLE and SIZEOF_LONG_DOUBLE But they are not portable across various tools.

Is there any way to do this?

+6
source share
3 answers

You can compare DBL_MANT_DIG and LDBL_MANT_DIG with float.h .

+5
source

You can check for example.

 #if DBL_MANT_DIG < LDBL_MANT_DIG 

or similar values ​​defined in float.h

+1
source

The “correct” solution to this problem (as used by many projects) is to create a script configuration.

The configuration script performs various tests, which include compiling and running small programs to determine the properties of the compiler and the system. The script then writes the data as a header file or makefile, or both. Of course, yours can do whatever you like.

There are tools, tools for these kinds of operations, semi-automatic, but they are probably too crowded for you. If you want to take a look, the names will be autoconf and automake. Beware, they are not easy to learn, but they generate configure and make scripts that should work on almost any platform if it has a unix-style shell and GNU make.

0
source

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


All Articles