@@ -94,6 +94,12 @@ SELECT negative(-1.5::double);
9494query R
9595SELECT negative(0.0::float);
9696----
97+ -0.0
98+
99+ # Test negative with negative zero float
100+ query R
101+ SELECT negative(-0.0::float);
102+ ----
971030.0
98104
99105# Test negative with decimal
@@ -147,30 +153,55 @@ SELECT negative(1234567890.123456::double);
147153----
148154-1234567890.123456
149155
150- # Test wrap-around: negative of minimum int (should overflow)
156+ # Test wrap-around: negative of minimum int (should wrap to same value)
157+ # Using table to avoid constant folding overflow during optimization
158+ statement ok
159+ CREATE TABLE min_values_int AS VALUES (-2147483648);
160+
151161query I
152- SELECT negative(-2147483648 ::int);
162+ SELECT negative(column1 ::int) FROM min_values_int ;
153163----
154164-2147483648
155165
156- # Test wrap-around: negative of minimum bigint (should overflow)
166+ statement ok
167+ DROP TABLE min_values_int;
168+
169+ # Test wrap-around: negative of minimum bigint (should wrap to same value)
170+ statement ok
171+ CREATE TABLE min_values_bigint AS VALUES (-9223372036854775808);
172+
157173query I
158- SELECT negative(-9223372036854775808 ::bigint);
174+ SELECT negative(column1 ::bigint) FROM min_values_bigint ;
159175----
160176-9223372036854775808
161177
162- # Test wrap-around: negative of minimum smallint (should overflow)
178+ statement ok
179+ DROP TABLE min_values_bigint;
180+
181+ # Test wrap-around: negative of minimum smallint (should wrap to same value)
182+ statement ok
183+ CREATE TABLE min_values_smallint AS VALUES (-32768);
184+
163185query I
164- SELECT negative(-32768 ::smallint);
186+ SELECT negative(column1 ::smallint) FROM min_values_smallint ;
165187----
166188-32768
167189
168- # Test wrap-around: negative of minimum tinyint (should overflow)
190+ statement ok
191+ DROP TABLE min_values_smallint;
192+
193+ # Test wrap-around: negative of minimum tinyint (should wrap to same value)
194+ statement ok
195+ CREATE TABLE min_values_tinyint AS VALUES (-128);
196+
169197query I
170- SELECT negative(-128 ::tinyint);
198+ SELECT negative(column1 ::tinyint) FROM min_values_tinyint ;
171199----
172200-128
173201
202+ statement ok
203+ DROP TABLE min_values_tinyint;
204+
174205# Test overflow: negative of positive infinity (float)
175206query R
176207SELECT negative('Infinity'::float);
@@ -211,13 +242,13 @@ NaN
211242query R
212243SELECT negative(3.4028235e38::float);
213244----
214- -3.4028235e38
245+ -340282350000000000000000000000000000000
215246
216247# Test overflow: negative of minimum float value
217248query R
218249SELECT negative(-3.4028235e38::float);
219250----
220- 3.4028235e38
251+ 340282350000000000000000000000000000000
221252
222253# Test overflow: negative of maximum double value
223254query R
0 commit comments