Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: OxCp syntax ? |
| Date | 2012-08-28 09:00 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <k1ifdp$v35$1@dont-email.me> (permalink) |
| References | <k1ia14$kjn$1@ccpntc8.in2p3.fr> |
On 08/28/2012 07:28 AM, Guillaume Dargaud wrote: > Hello all, > I just ran across this syntax: > #define NAN 0xCp125f > Can somebody explain ? A quick googling turned out nothing. C99 added the capability of specifying floating point constants using hexadecimal notation. They are case-insensitive, just like hexadecimal constants and decimal floating point constants. The 0x is the hexadecimal prefix. "C" is the hexadecimal digit sequence, corresponding to a decimal value of 13. 'p' is the separator, corresponding to "e" in decimal floating point constants. 125 is the exponent. "f" is a suffix indicating that this constant has the type 'float'. This particular constant represents a float value of 0xC*2^125. Compare to 5e60, which represents 5*10^60. Fractional parts are also allowed, but unlike decimal floating point constants, the binary exponent part cannot be dropped: #define PI 0x3.243F6A88p0 One of the most important characteristics of hexadecimal floating point constants is explained in 6.4.4.2p3: > ... For decimal floating constants, and also for > hexadecimal floating constants when FLT_RADIX is not a power of 2, the result is either > the nearest representable value, or the larger or smaller representable value immediately > adjacent to the nearest representable value, chosen in an implementation-defined manner. > For hexadecimal floating constants when FLT_RADIX is a power of 2, the result is > correctly rounded. ... Almost all real-world implementations of C have a power of 2 for FLT_RADIX, so this guarantee means that using a hexadecimal floating point value gives you more precise control over the value that it represents than a decimal floating point value would. Note: it's not clear to me that, on a system which supports true NaNs, that 0xCp125f could be a NaN. If 0xC*2^125 is representable, then by definition it isn't a NaN. If it is not representable, then a diagnostic is required (the behavior being undefined at that point, it would be permissible for a true NaN to be generated). However, if you ran into this definition inside of <math.h>, then I might be wrong about that. -- James Kuyper
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
OxCp syntax ? Guillaume Dargaud <use_the_contact_form@www.gdargaud.net> - 2012-08-28 13:28 +0200
Re: OxCp syntax ? Les Cargill <lcargill99@comcast.com> - 2012-08-28 07:30 -0500
Re: OxCp syntax ? Les Cargill <lcargill99@comcast.com> - 2012-08-28 07:41 -0500
Re: OxCp syntax ? James Kuyper <jameskuyper@verizon.net> - 2012-08-28 09:00 -0400
Re: OxCp syntax ? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-28 09:10 -0400
Re: OxCp syntax ? James Kuyper <jameskuyper@verizon.net> - 2012-08-28 09:58 -0400
Re: OxCp syntax ? Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-28 09:02 -0400
Re: OxCp syntax ? Vincenzo Mercuri <vincenzo.mercuri@yahoo.it> - 2012-08-29 19:16 +0200
Re: OxCp syntax ? Nobody <nobody@nowhere.com> - 2012-08-28 14:17 +0100
Re: OxCp syntax ? Guillaume Dargaud <use_the_contact_form@www.gdargaud.net> - 2012-08-29 17:50 +0200
csiph-web