--
-- INT2
--
-- corner cases
SELECT (-1::int2<<15)::text;
 column0 
---------
 -32768
(1 row)

SELECT ((-1::int2<<15)+1::int2)::text;
 column0 
---------
 -32767
(1 row)

-- check sane handling of INT16_MIN overflow cases
SELECT (-32768)::int2 * (-1)::int2;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/int2.sql:10: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(30): ERROR:  smallint out of range



SELECT (-32768)::int2 / (-1)::int2;
psql:/home/runner/.ya/build/build_root/f6zk/0031e5/environment/arcadia/ydb/tests/functional/postgresql/cases/int2.sql:11: Status: PRECONDITION_FAILED
Issues: 
<main>: Error: Terminate was called, reason(30): ERROR:  smallint out of range



SELECT (-32768)::int2 % (-1)::int2;
 column0 
---------
       0
(1 row)

-- check rounding when casting from float
SELECT x, x::int2 AS int2_value
FROM (VALUES (-2.5::float8),
             (-1.5::float8),
             (-0.5::float8),
             (0.0::float8),
             (0.5::float8),
             (1.5::float8),
             (2.5::float8)) t(x);
  x   | int2_value 
------+------------
 -2.5 |         -2
 -1.5 |         -2
 -0.5 |          0
    0 |          0
  0.5 |          0
  1.5 |          2
  2.5 |          2
(7 rows)

-- check rounding when casting from numeric
SELECT x, x::int2 AS int2_value
FROM (VALUES (-2.5::numeric),
             (-1.5::numeric),
             (-0.5::numeric),
             (0.5::numeric),
             (1.5::numeric),
             (2.5::numeric)) t(x);
  x   | int2_value 
------+------------
 -2.5 |         -3
 -1.5 |         -2
 -0.5 |         -1
  0.5 |          1
  1.5 |          2
  2.5 |          3
(6 rows)

