解决ceil函数嵌套tan函数可能返回-0的问题

This commit is contained in:
liruixiang
2022-12-02 19:34:22 +08:00
parent 6412f131ab
commit 5c29e59612
4 changed files with 80 additions and 1 deletions

View File

@ -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);
}
/*

View 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;

View File

@ -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

View 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;