mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
Describe standard float/double support.
Rewrite example to be an interactive session
This commit is contained in:
parent
b9a781e177
commit
dbadd558b5
2 changed files with 20 additions and 12 deletions
|
@ -101,8 +101,8 @@ expression. This is always combined with native byte order.
|
||||||
|
|
||||||
Standard size and alignment are as follows: no alignment is required
|
Standard size and alignment are as follows: no alignment is required
|
||||||
for any type (so you have to use pad bytes); short is 2 bytes; int and
|
for any type (so you have to use pad bytes); short is 2 bytes; int and
|
||||||
long are 4 bytes. In this mode, there is no support for float and
|
long are 4 bytes. Float and double are 32-bit and 64-bit IEEE floating
|
||||||
double (\code{'f'} and \code{'d'}).
|
point numbers, respectively.
|
||||||
|
|
||||||
Note the difference between \code{'@'} and \code{'='}: both use native
|
Note the difference between \code{'@'} and \code{'='}: both use native
|
||||||
byte order, but the size and alignment of the latter is standardized.
|
byte order, but the size and alignment of the latter is standardized.
|
||||||
|
@ -119,10 +119,14 @@ Examples (all using native byte order, size and alignment, on a
|
||||||
big-endian machine):
|
big-endian machine):
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\bcode\begin{verbatim}
|
||||||
from struct import *
|
>>> from struct import *
|
||||||
pack('hhl', 1, 2, 3) == '\000\001\000\002\000\000\000\003'
|
>>> pack('hhl', 1, 2, 3)
|
||||||
unpack('hhl', '\000\001\000\002\000\000\000\003') == (1, 2, 3)
|
'\000\001\000\002\000\000\000\003'
|
||||||
calcsize('hhl') == 8
|
>>> unpack('hhl', '\000\001\000\002\000\000\000\003')
|
||||||
|
(1, 2, 3)
|
||||||
|
>>> calcsize('hhl')
|
||||||
|
8
|
||||||
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}\ecode
|
||||||
|
|
||||||
Hint: to align the end of a structure to the alignment requirement of
|
Hint: to align the end of a structure to the alignment requirement of
|
||||||
|
|
|
@ -101,8 +101,8 @@ expression. This is always combined with native byte order.
|
||||||
|
|
||||||
Standard size and alignment are as follows: no alignment is required
|
Standard size and alignment are as follows: no alignment is required
|
||||||
for any type (so you have to use pad bytes); short is 2 bytes; int and
|
for any type (so you have to use pad bytes); short is 2 bytes; int and
|
||||||
long are 4 bytes. In this mode, there is no support for float and
|
long are 4 bytes. Float and double are 32-bit and 64-bit IEEE floating
|
||||||
double (\code{'f'} and \code{'d'}).
|
point numbers, respectively.
|
||||||
|
|
||||||
Note the difference between \code{'@'} and \code{'='}: both use native
|
Note the difference between \code{'@'} and \code{'='}: both use native
|
||||||
byte order, but the size and alignment of the latter is standardized.
|
byte order, but the size and alignment of the latter is standardized.
|
||||||
|
@ -119,10 +119,14 @@ Examples (all using native byte order, size and alignment, on a
|
||||||
big-endian machine):
|
big-endian machine):
|
||||||
|
|
||||||
\bcode\begin{verbatim}
|
\bcode\begin{verbatim}
|
||||||
from struct import *
|
>>> from struct import *
|
||||||
pack('hhl', 1, 2, 3) == '\000\001\000\002\000\000\000\003'
|
>>> pack('hhl', 1, 2, 3)
|
||||||
unpack('hhl', '\000\001\000\002\000\000\000\003') == (1, 2, 3)
|
'\000\001\000\002\000\000\000\003'
|
||||||
calcsize('hhl') == 8
|
>>> unpack('hhl', '\000\001\000\002\000\000\000\003')
|
||||||
|
(1, 2, 3)
|
||||||
|
>>> calcsize('hhl')
|
||||||
|
8
|
||||||
|
>>>
|
||||||
\end{verbatim}\ecode
|
\end{verbatim}\ecode
|
||||||
|
|
||||||
Hint: to align the end of a structure to the alignment requirement of
|
Hint: to align the end of a structure to the alignment requirement of
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue