From e63a0e277c36492da86175467c10963cc0ab07e9 Mon Sep 17 00:00:00 2001 From: wangjiaming0909 <604227650@qq.com> Date: Fri, 13 Dec 2024 16:01:04 +0800 Subject: [PATCH] decimal: add decimal.c --- include/libs/decimal/decimal.h | 32 ++++++++++++++++++++++++++++++ source/libs/decimal/CMakeLists.txt | 16 +++++++++++++++ source/libs/decimal/src/decimal.c | 27 +++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 include/libs/decimal/decimal.h create mode 100644 source/libs/decimal/CMakeLists.txt create mode 100644 source/libs/decimal/src/decimal.c diff --git a/include/libs/decimal/decimal.h b/include/libs/decimal/decimal.h new file mode 100644 index 0000000000..a56e241ccc --- /dev/null +++ b/include/libs/decimal/decimal.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#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_*/ diff --git a/source/libs/decimal/CMakeLists.txt b/source/libs/decimal/CMakeLists.txt new file mode 100644 index 0000000000..6837ae8eb1 --- /dev/null +++ b/source/libs/decimal/CMakeLists.txt @@ -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}) diff --git a/source/libs/decimal/src/decimal.c b/source/libs/decimal/src/decimal.c new file mode 100644 index 0000000000..49bb2b8433 --- /dev/null +++ b/source/libs/decimal/src/decimal.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#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; +} + +