添加float精确度接口
parent
72e20c74ae
commit
9a1f5494b3
|
@ -35,5 +35,8 @@ inline ENV_COMPILER CurrentEnvCompiler();
|
|||
string itos(int x);
|
||||
|
||||
|
||||
// 限制float精确度
|
||||
float LimitFloat(float in,int size);
|
||||
|
||||
|
||||
#endif //CUTILS_UTILS_H
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
//
|
||||
// Created by 29019 on 2020/1/4.
|
||||
//
|
||||
|
||||
#include "aes.h"
|
||||
#include <cstring>
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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 <<std::endl;
|
||||
|
||||
return float(integer)/tmp;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,27 @@ typedef struct testsize2{
|
|||
}Test2;
|
||||
#pragma pack()
|
||||
|
||||
// 限制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 <<std::endl;
|
||||
|
||||
return float(integer)/tmp;
|
||||
}
|
||||
|
||||
int main(){
|
||||
std::cout<<sizeof(Test1) << " "<< sizeof(Test2)<<std::endl;
|
||||
std::cout<< LimitFloat(1.123,2)<<std::endl;
|
||||
std::cout<<LimitFloat(1.123,3) << std::endl;
|
||||
std::cout<<LimitFloat(0.789,1) << std::endl;
|
||||
std::cout<<LimitFloat(0,3) << std::endl;
|
||||
|
||||
std::cout<<"\r\n"<<std::endl<<sizeof(Test1) << " "<< sizeof(Test2)<<std::endl;
|
||||
Test1 x = Test1{
|
||||
1,2,3
|
||||
};
|
||||
|
|
|
@ -58,11 +58,14 @@ void print_thread_id (int id) {
|
|||
|
||||
void TestLockGuard() {
|
||||
std::thread threads[10];
|
||||
// spawn 10 threads:
|
||||
for (int i=0; i<10; ++i)
|
||||
threads[i] = std::thread(print_thread_id,i+1);
|
||||
// spawn 10 threads:`
|
||||
for (int i = 0; i < 10; ++i)
|
||||
threads[i] = std::thread(
|
||||
print_thread_id,i+1
|
||||
);
|
||||
|
||||
for (auto& th : threads) th.join();
|
||||
for (auto& th : threads)
|
||||
th.join();
|
||||
|
||||
return ;
|
||||
}
|
||||
|
@ -307,7 +310,7 @@ int main()
|
|||
ASyncProcess<std::function<int(int)>,int,int> process([](int p) -> int{
|
||||
return 20;
|
||||
},result,150);
|
||||
while(process.Finish() == false){
|
||||
while(process.Finish() == false) {
|
||||
|
||||
}
|
||||
std::cout<<process.Finish() << " "<<result<<"\r\n";
|
||||
|
|
Loading…
Reference in New Issue