解决ceil函数嵌套tan函数可能返回-0的问题
This commit is contained in:
@ -1418,7 +1418,13 @@ Datum dceil(PG_FUNCTION_ARGS)
|
||||
{
|
||||
float8 arg1 = PG_GETARG_FLOAT8(0);
|
||||
|
||||
PG_RETURN_FLOAT8(ceil(arg1));
|
||||
float8 result = ceil(arg1);
|
||||
if (DB_IS_CMPT(A_FORMAT) && -0.0 == result) {
|
||||
/* ceil function won't return -0 if compatible with O type database */
|
||||
result = 0.0;
|
||||
}
|
||||
|
||||
PG_RETURN_FLOAT8(result);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
43
src/test/regress/expected/ceil_negtive_zero.out
Normal file
43
src/test/regress/expected/ceil_negtive_zero.out
Normal file
@ -0,0 +1,43 @@
|
||||
--
|
||||
-- 处理ceil函数返回-0问题
|
||||
--
|
||||
create database ceil_nzero_test DBCOMPATIBILITY 'A';
|
||||
\c ceil_nzero_test
|
||||
select ceil(tan(-0.5));
|
||||
ceil
|
||||
------
|
||||
0
|
||||
(1 row)
|
||||
|
||||
\c postgres
|
||||
drop database ceil_nzero_test;
|
||||
create database ceil_nzero_test DBCOMPATIBILITY 'B';
|
||||
\c ceil_nzero_test
|
||||
select ceil(tan(-0.5));
|
||||
ceil
|
||||
------
|
||||
-0
|
||||
(1 row)
|
||||
|
||||
\c postgres
|
||||
drop database ceil_nzero_test;
|
||||
create database ceil_nzero_test DBCOMPATIBILITY 'C';
|
||||
\c ceil_nzero_test
|
||||
select ceil(tan(-0.5));
|
||||
ceil
|
||||
------
|
||||
-0
|
||||
(1 row)
|
||||
|
||||
\c postgres
|
||||
drop database ceil_nzero_test;
|
||||
create database ceil_nzero_test DBCOMPATIBILITY 'PG';
|
||||
\c ceil_nzero_test
|
||||
select ceil(tan(-0.5));
|
||||
ceil
|
||||
------
|
||||
-0
|
||||
(1 row)
|
||||
|
||||
\c postgres
|
||||
drop database ceil_nzero_test;
|
||||
@ -1028,6 +1028,9 @@ test: gsbasebackup_options
|
||||
test: gsdump_options
|
||||
test: gsloader_options
|
||||
|
||||
# debug ceil(-0.5) -0
|
||||
test: ceil_negtive_zero
|
||||
|
||||
# dolphin_guc_config
|
||||
test: dolphin_guc_config
|
||||
|
||||
|
||||
27
src/test/regress/sql/ceil_negtive_zero.sql
Normal file
27
src/test/regress/sql/ceil_negtive_zero.sql
Normal file
@ -0,0 +1,27 @@
|
||||
--
|
||||
-- 处理ceil函数返回-0问题
|
||||
--
|
||||
|
||||
create database ceil_nzero_test DBCOMPATIBILITY 'A';
|
||||
\c ceil_nzero_test
|
||||
select ceil(tan(-0.5));
|
||||
\c postgres
|
||||
drop database ceil_nzero_test;
|
||||
|
||||
create database ceil_nzero_test DBCOMPATIBILITY 'B';
|
||||
\c ceil_nzero_test
|
||||
select ceil(tan(-0.5));
|
||||
\c postgres
|
||||
drop database ceil_nzero_test;
|
||||
|
||||
create database ceil_nzero_test DBCOMPATIBILITY 'C';
|
||||
\c ceil_nzero_test
|
||||
select ceil(tan(-0.5));
|
||||
\c postgres
|
||||
drop database ceil_nzero_test;
|
||||
|
||||
create database ceil_nzero_test DBCOMPATIBILITY 'PG';
|
||||
\c ceil_nzero_test
|
||||
select ceil(tan(-0.5));
|
||||
\c postgres
|
||||
drop database ceil_nzero_test;
|
||||
Reference in New Issue
Block a user