From 9a1f5494b3b84752cd98da159664c48940d4e140 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Wed, 5 Jan 2022 16:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0float=E7=B2=BE=E7=A1=AE?= =?UTF-8?q?=E5=BA=A6=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- general/inc/utils.h | 3 +++ general/src/encrypt/aes.cpp | 3 --- general/src/loger.cpp | 3 ++- general/src/utils.cpp | 14 ++++++++++++++ test/src/cpp11/log_test.cpp | 21 ++++++++++++++++++++- test/src/cpp11/thread_usage.cpp | 13 ++++++++----- 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/general/inc/utils.h b/general/inc/utils.h index 340b4c4..58e2ba8 100644 --- a/general/inc/utils.h +++ b/general/inc/utils.h @@ -35,5 +35,8 @@ inline ENV_COMPILER CurrentEnvCompiler(); string itos(int x); +// 限制float精确度 +float LimitFloat(float in,int size); + #endif //CUTILS_UTILS_H diff --git a/general/src/encrypt/aes.cpp b/general/src/encrypt/aes.cpp index 153da32..e643343 100644 --- a/general/src/encrypt/aes.cpp +++ b/general/src/encrypt/aes.cpp @@ -1,6 +1,3 @@ -// -// Created by 29019 on 2020/1/4. -// #include "aes.h" #include diff --git a/general/src/loger.cpp b/general/src/loger.cpp index 4565893..f8b56e1 100644 --- a/general/src/loger.cpp +++ b/general/src/loger.cpp @@ -116,6 +116,7 @@ int Loger::Error(string dat,string function,int line) { return 0; } + int Loger::Warning(string dat,string function,int line) { if(mLevel > LEVEL_WARNING) { return 0; @@ -343,7 +344,7 @@ Loger::Loger(string path,string prefix,bool old) { }else{ this->mFile = fopen(this->mCurrentPath.c_str(),"a+"); } - if(! this->mFile){ + if(!this->mFile){ fprintf(stderr,"error open log files %s code %d,please check file path",this->mCurrentPath.c_str(),errno); exit(0); }else{ diff --git a/general/src/utils.cpp b/general/src/utils.cpp index a516e61..f2a2d93 100644 --- a/general/src/utils.cpp +++ b/general/src/utils.cpp @@ -62,3 +62,17 @@ inline ENV_COMPILER CurrentEnvCompiler() } + +// 限制float有效位 +float LimitFloat(float in,int size){ + uint64_t tmp = 1; + for(int i = 0;i < size;i++){ + tmp = tmp*10; + } + uint64_t integer = uint64_t(in * tmp); // 提取整数部分 + + uint64_t decimal = integer %tmp; // 提取小数部分 + std::cout<< "float_limit " << in<< " "<< integer << " "<< decimal << " "<< tmp <,int,int> process([](int p) -> int{ return 20; },result,150); - while(process.Finish() == false){ + while(process.Finish() == false) { } std::cout<