Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect if long double is of extended precision or not at compile time

On few systems double is same as long double. How can I detect if long double is of extended precision than double at compile time and use it to conditional compile.

I see there are predefined macros present in libgcc SIZEOF_DOUBLE and SIZEOF_LONG_DOUBLE But there are not portable across different toolchains.

Is there C way to do this?

like image 889
kanna Avatar asked Jan 05 '12 22:01

kanna


2 Answers

You could compare DBL_MANT_DIG and LDBL_MANT_DIG from float.h.

like image 91
David Heffernan Avatar answered Sep 20 '22 07:09

David Heffernan


You can test e.g.

#if DBL_MANT_DIG < LDBL_MANT_DIG

or similar values defined in float.h

like image 40
Daniel Fischer Avatar answered Sep 23 '22 07:09

Daniel Fischer