Skip to content

Commit 9ce3ca3

Browse files
committed
gh-143674: document complex representation using f/d formats in struct
1 parent 3b172c4 commit 9ce3ca3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

Doc/library/struct.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ platform-dependent.
280280
.. versionchanged:: 3.14
281281
Added support for the ``'F'`` and ``'D'`` formats.
282282

283+
Complex numbers may also be represented using two consecutive floating-point
284+
format characters. In this case, the real part is stored first, followed by
285+
the imaginary part. The format characters ``f`` and ``d`` determine the type
286+
used for each component.
283287

284288
Notes:
285289

Modules/_struct.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2688,7 +2688,9 @@ these can be preceded by a decimal repeat count:\n\
26882688
x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;\n\
26892689
?: _Bool (requires C99; if not available, char is used instead)\n\
26902690
h:short; H:unsigned short; i:int; I:unsigned int;\n\
2691-
l:long; L:unsigned long; f:float; d:double; e:half-float.\n\
2691+
l:long; L:unsigned long; f:float; d:double; e:half-float.\n\
2692+
For complex numbers, the real and imaginary parts are represented by two\n\
2693+
consecutive values of the specified floating-point type.\n\
26922694
Special cases (preceding decimal count indicates length):\n\
26932695
s:string (array of char); p: pascal string (with count byte).\n\
26942696
Special cases (only available in native format):\n\

0 commit comments

Comments
 (0)