decimal: add decimal.c

This commit is contained in:
wangjiaming0909 2024-12-13 16:01:04 +08:00 committed by wangjiaming0909
parent 1273d1a816
commit e63a0e277c
3 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_DECIMAL_H_
#define _TD_DECIMAL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "tdef.h"
typedef struct SDataType SDataType;
int32_t decimalCalcTypeMod(const SDataType* pType);
#ifdef __cplusplus
}
#endif
#endif /*_TD_DECIMAL_H_*/

View File

@ -0,0 +1,16 @@
aux_source_directory(src DECIMAL_SRC)
add_library(decimal STATIC ${DECIMAL_SRC})
target_include_directories(
decimal
PUBLIC "${TD_SOURCE_DIR}/include/libs/decimal"
)
target_link_libraries(
decimal
PRIVATE os util common qcom nodes
)
if(${BUILD_TEST})
ADD_SUBDIRECTORY(test)
endif(${BUILD_TEST})

View File

@ -0,0 +1,27 @@
/*
*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "decimal.h"
#include "querynodes.h"
int32_t decimalCalcTypeMod(const SDataType* pType) {
if (IS_DECIMAL_TYPE(pType->type)) {
return (pType->precision << 8) + pType->scale;
}
return 0;
}