Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbadd55

Browse files
committed
Describe standard float/double support.
Rewrite example to be an interactive session
1 parent b9a781e commit dbadd55

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

Doc/lib/libstruct.tex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ \section{Built-in Module \sectcode{struct}}
101101

102102
Standard size and alignment are as follows: no alignment is required
103103
for any type (so you have to use pad bytes); short is 2 bytes; int and
104-
long are 4 bytes. In this mode, there is no support for float and
105-
double (\code{'f'} and \code{'d'}).
104+
long are 4 bytes. Float and double are 32-bit and 64-bit IEEE floating
105+
point numbers, respectively.
106106

107107
Note the difference between \code{'@'} and \code{'='}: both use native
108108
byte order, but the size and alignment of the latter is standardized.
@@ -119,10 +119,14 @@ \section{Built-in Module \sectcode{struct}}
119119
big-endian machine):
120120

121121
\bcode\begin{verbatim}
122-
from struct import *
123-
pack('hhl', 1, 2, 3) == '\000\001\000\002\000\000\000\003'
124-
unpack('hhl', '\000\001\000\002\000\000\000\003') == (1, 2, 3)
125-
calcsize('hhl') == 8
122+
>>> from struct import *
123+
>>> pack('hhl', 1, 2, 3)
124+
'\000\001\000\002\000\000\000\003'
125+
>>> unpack('hhl', '\000\001\000\002\000\000\000\003')
126+
(1, 2, 3)
127+
>>> calcsize('hhl')
128+
8
129+
>>>
126130
\end{verbatim}\ecode
127131

128132
Hint: to align the end of a structure to the alignment requirement of

Doc/libstruct.tex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ \section{Built-in Module \sectcode{struct}}
101101

102102
Standard size and alignment are as follows: no alignment is required
103103
for any type (so you have to use pad bytes); short is 2 bytes; int and
104-
long are 4 bytes. In this mode, there is no support for float and
105-
double (\code{'f'} and \code{'d'}).
104+
long are 4 bytes. Float and double are 32-bit and 64-bit IEEE floating
105+
point numbers, respectively.
106106

107107
Note the difference between \code{'@'} and \code{'='}: both use native
108108
byte order, but the size and alignment of the latter is standardized.
@@ -119,10 +119,14 @@ \section{Built-in Module \sectcode{struct}}
119119
big-endian machine):
120120

121121
\bcode\begin{verbatim}
122-
from struct import *
123-
pack('hhl', 1, 2, 3) == '\000\001\000\002\000\000\000\003'
124-
unpack('hhl', '\000\001\000\002\000\000\000\003') == (1, 2, 3)
125-
calcsize('hhl') == 8
122+
>>> from struct import *
123+
>>> pack('hhl', 1, 2, 3)
124+
'\000\001\000\002\000\000\000\003'
125+
>>> unpack('hhl', '\000\001\000\002\000\000\000\003')
126+
(1, 2, 3)
127+
>>> calcsize('hhl')
128+
8
129+
>>>
126130
\end{verbatim}\ecode
127131

128132
Hint: to align the end of a structure to the alignment requirement of

0 commit comments

Comments
 (0)