How to get the largest precision floating point data type of implemenation and its printf specifier?

Or put differently, are there equivalents to intmax_t and %jd but for floating point numbers?

This has already been asked as a side question here, but the question is so large that I think people forgot to answer the side question. Also that was tagged as c++, and I'm looking for a c solution.

Related questions:

Upvotes: 3

Views: 1454

Answers (2)

chux
chux

Reputation: 153338

C11 does not have a floating point equivalents to intmax_t (Integer type with the maximum width supported.). Should C of the future define some sort of long long double, etc. the language presently has no seamless upgrade path to it.

C11 6.11.1.1 "Future standardization may include additional floating-point types, including those with greater range, precision, or both than long double." does point to the possibility of larger widths you envision.

The situation for floating-point numbers differs from integers in need. Various processors have had increasingly width integer widths over the years (8,16,32,64) and 128 on the horizon. Whereas gross floating-point size has been relatively more stable (4,8,10,16) , precision, range, encoding, rounding have taken up much FP concern. I suspect we'll see decimal and binary floating point specifications next.

Another difference is that integers grow in one dimension - range. FP can grow independently in range and precision, not to mention the peculiarities of base (2, 10, 16, etc.) Also see "IEEE 754" comment below.

Presently we have 3: C11 6.2.5.4 : float, double, and long double. Should you want to create a forward compatibly path you could prepare for a change with say typedef long double Xdouble, but then you may be obliged to write a lot of wrapper functions like Xdouble sinX(Xdouble x);, prepare many equivalent defines to DBL_MANT_DIG, PRIdN, etc. No small effort.

Upvotes: 2

R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215193

To my knowledge C does not have extended floating point types. The only floating point types are float, double, and long double. Thus, %La, %Le, %Lf, %Lg, and long double seem to be your answers.

Some implementations may provide additional extended types, but they are completely outside the scope of the standard.

Upvotes: 4

Related Questions