@@ -730,6 +730,30 @@ SELECT a, ceil(a), ceiling(a), floor(a), round(a) FROM ceil_floor_round;
730
730
(7 rows)
731
731
732
732
DROP TABLE ceil_floor_round;
733
+ -- Check rounding, it should round ties away from zero.
734
+ SELECT i as pow,
735
+ round((-2.5 * 10 ^ i)::numeric, -i),
736
+ round((-1.5 * 10 ^ i)::numeric, -i),
737
+ round((-0.5 * 10 ^ i)::numeric, -i),
738
+ round((0.5 * 10 ^ i)::numeric, -i),
739
+ round((1.5 * 10 ^ i)::numeric, -i),
740
+ round((2.5 * 10 ^ i)::numeric, -i)
741
+ FROM generate_series(-5,5) AS t(i);
742
+ pow | round | round | round | round | round | round
743
+ -----+----------+----------+----------+---------+---------+---------
744
+ -5 | -0.00003 | -0.00002 | -0.00001 | 0.00001 | 0.00002 | 0.00003
745
+ -4 | -0.0003 | -0.0002 | -0.0001 | 0.0001 | 0.0002 | 0.0003
746
+ -3 | -0.003 | -0.002 | -0.001 | 0.001 | 0.002 | 0.003
747
+ -2 | -0.03 | -0.02 | -0.01 | 0.01 | 0.02 | 0.03
748
+ -1 | -0.3 | -0.2 | -0.1 | 0.1 | 0.2 | 0.3
749
+ 0 | -3 | -2 | -1 | 1 | 2 | 3
750
+ 1 | -30 | -20 | -10 | 10 | 20 | 30
751
+ 2 | -300 | -200 | -100 | 100 | 200 | 300
752
+ 3 | -3000 | -2000 | -1000 | 1000 | 2000 | 3000
753
+ 4 | -30000 | -20000 | -10000 | 10000 | 20000 | 30000
754
+ 5 | -300000 | -200000 | -100000 | 100000 | 200000 | 300000
755
+ (11 rows)
756
+
733
757
-- Testing for width_bucket(). For convenience, we test both the
734
758
-- numeric and float8 versions of the function in this file.
735
759
-- errors
0 commit comments