postgres.git / summary / log / commit / refs
commit 45277ca0d1cb6dbe722a01b3b5461c30abd40eee
Author: David Rowley <drowley@postgresql.org>
Date: Thu Oct 01 02:15:58 2026 +0000
Doc: mention platform-dependent behavior of bitshift operators
There have been several recent complaints that << and >> don't behave
the same way on all supported platforms. There is a risk that <<
overflows the signed integer type, which is undefined behavior, and there
are platform-dependent behaviors from shifting by numbers of bits >= the
bitwidth of the type, and also from shifting by negative values.
Document this to warn unsuspecting users of these facts.
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAApHDvr0O6ZF8NO=Rq9Q+Sz=FHT=NZ1kkNTXZDcNph-OWuk7TQ@mail.gmail.com
Backpatch-through: 14
doc/src/sgml/func/func-math.sgml | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/doc/src/sgml/func/func-math.sgml b/doc/src/sgml/func/func-math.sgml
index 9dcf97e7c9e..4b5d587b368 100644
--- a/doc/src/sgml/func/func-math.sgml
+++ b/doc/src/sgml/func/func-math.sgml
@@ -26,6 +26,13 @@
are resolved by using the type appearing later in these lists.
</para>
+ <para>
+ The behavior of bitwise shifting, both left and right, has
+ platform-dependent behavior both in cases of left shifting that results in
+ a signed overflow and in cases of the results of shifting by more bits
+ than exist in the type or from shifting by a negative value.
+ </para>
+
<table id="functions-math-op-table">
<title>Mathematical Operators</title>
[parent: a36e2f7cd21c]