简体   繁体   中英

Format specifier %F missing from glibc's documentation

I stumbled upon the following deficiency in the GNU C Library's documentation :

'%f'

Print a floating-point number in normal (fixed-point) notation. See Floating-Point Conversions, for details.

And it does not mention %F anywhere, although according to the C99 standard :

The F conversion specifier produces INF, INFINITY, or NAN instead of inf, infinity, or nan, respectively.

A simple example to test this:

double inf = 1.0 / 0.0;
printf( "Testing on %ld.%ld, %%f: %f and %%F: %F.\n", __GLIBC__, __GLIBC_MINOR__, inf, inf );

This outputs:

Testing on 2.24, %f: inf and %F: INF.

So it works as it should, not as the documentation says.

I was thinking why the capital F feature is not in the documentation. Does it make sense? Yes. Does it comply with the standard? Yes. Is it be implemented? Yes. So, I don't see the reason.

Is there a convention that issues regulated by the standard are automatically considered part of the library documentation? Is it safe to use %F in a printf format?

That various open source projects come with incomplete or incorrect documentation isn't exactly news. The documentation is simply missing this information indeed.

The 2.36 documentation is also missing this info. Conclusion: the documentation is bad.

And yes %F is perfectly safe and well-defined as per C99. For very old compiler versions (such as gcc < 5.0.0) you should compile with -std=c99 however.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM