What is p-notation in C programming?

I'm learning C right now, and there is a conversion specifier% a that writes the number in p-notation, unlike% e, which writes something in e-notation (exponential notation).

What is p-notation?

+3
source share
5 answers

You use %ato get the hexadecimal representation of a floating point number. This can be useful if you are participating in studies with floating point representations or want you to be able to read and write the exact floating point number without a rounding error (but not very clear to the person).

, , C99. Dinkumware C99 ; PJ Plauger, C89 C99. - ; http://www.dinkumware.com/manuals/default.aspx

+7

c99, 7.19.6.1 (7), % a % A ( mac, dmckee ):

, [-] 0xh.hhhhp ± d, ( , ) ; , FLT_RADIX - 2, ; , FLT_RADIX 2, 248) double, , ; # , . abcdef ABCDEF . A specifier X P x p. , , 2. , .

+5

man- printf(3) Mac OS X (, BSD c):


     nota-               [-] 0xh.hhhp [+ -] d,               ,              . ,              , ,               . ,               . P p', and the exponent consists of a positive or negative sign followed by a decimal number representing an exponent of 2. The A conversion uses the prefix ``0X'' (rather than ``0x''), the letters ``ABCDEF'' (rather than ``abcdef'') to represent the hex digits, and the letter P '( `p')              .

"p" ( "P" ) () () .

K & R, man- , ( ) .

Debian 5.0 ( glibc 2.7), ; , c99 ( , - ).

+3

%a ( , , , - ).

%p, .

.

: . .

+2

: http://www.cppreference.com/wiki/c/io/printf

In particular, here are the format specifiers that you can use in printf (without modifiers like .02, etc.):

Code    Format
%c  character
%d  signed integers
%i  signed integers
%I64d   long long (8B integer), MS-specific
%I64u   unsigned long long (8B integer), MS-specific
%e  scientific notation, with a lowercase "e"
%E  scientific notation, with a uppercase "E"
%f  floating point
%g  use %e or %f, whichever is shorter
%G  use %E or %f, whichever is shorter
%o  octal
%s  a string of characters
%u  unsigned integer
%x  unsigned hexadecimal, with lowercase letters
%X  unsigned hexadecimal, with uppercase letters
%p  a pointer
%n  the argument shall be a pointer to an integer into which is placed the number of characters written so far
+1
source

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


All Articles