#include <limits.h>
#include <ctype.h>
+/*
+ * Defining INT64_MIN as -9223372036854775808LL may not work; the compiler's
+ * tokenizer may see - as a separate token and then be unable to view
+ * 9223372036854775808 as a number. This is the standard workaround for that
+ * problem.
+ */
+#ifndef INT64_MIN
+#define INT64_MIN (-9223372036854775807LL - 1)
+#endif
+
#include "utils/builtins.h"
/*
* Avoid problems with the most negative integer not being representable
* as a positive integer.
*/
- if (value == INT32_MIN)
+ if (value == INT_MIN)
{
memcpy(a, "-2147483648", 12);
return;
(5 rows)
-- corner cases
-SELECT (1<<15-1)::int2::text;
- text
--------
- 16384
+SELECT (-1::int2<<15)::text;
+ text
+--------
+ -32768
(1 row)
-SELECT (-1<<15)::int2::text;
+SELECT ((-1::int2<<15)+1)::text;
text
--------
- -32768
+ -32767
(1 row)
2
(1 row)
--- corner cases
-SELECT (1<<31-1)::int4::text;
- text
-------------
- 1073741824
+-- corner case
+SELECT (-1::int4<<31)::text;
+ text
+-------------
+ -2147483648
(1 row)
-SELECT (1<<31)::int4::text;
+SELECT ((-1::int4<<31)+1)::text;
text
-------------
- -2147483648
+ -2147483647
(1 row)
4567890123456799
(6 rows)
--- corner cases
-SELECT (1<<63-1)::int8::text;
- text
-------------
- 1073741824
+-- corner case
+SELECT (-1::int8<<63)::text;
+ text
+----------------------
+ -9223372036854775808
(1 row)
-SELECT (1<<63)::int8::text;
- text
--------------
- -2147483648
+SELECT ((-1::int8<<63)+1)::text;
+ text
+----------------------
+ -9223372036854775807
(1 row)
SELECT '' AS five, i.f1, i.f1 / int4 '2' AS x FROM INT2_TBL i;
-- corner cases
-SELECT (1<<15-1)::int2::text;
-SELECT (-1<<15)::int2::text;
+SELECT (-1::int2<<15)::text;
+SELECT ((-1::int2<<15)+1)::text;
SELECT (2 + 2) / 2 AS two;
--- corner cases
-SELECT (1<<31-1)::int4::text;
-SELECT (1<<31)::int4::text;
+-- corner case
+SELECT (-1::int4<<31)::text;
+SELECT ((-1::int4<<31)+1)::text;
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 0);
SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 2);
--- corner cases
-SELECT (1<<63-1)::int8::text;
-SELECT (1<<63)::int8::text;
+-- corner case
+SELECT (-1::int8<<63)::text;
+SELECT ((-1::int8<<63)+1)::text;