added HalfFloatTest.cpp,removed ColorTest.cpp

This commit is contained in:
HuYingzhuo(hugo/hyzboy) 2023-02-09 14:29:09 +08:00
parent 5d9edc35c8
commit 3281e6eefd
3 changed files with 63 additions and 23 deletions

View File

@ -15,8 +15,8 @@ macro(cm_example_project project_name)
set_property(TARGET ${project_name} PROPERTY FOLDER "CM/Examples")
endmacro()
add_executable(ColorTest ColorTest.cpp)
cm_example_project(ColorTest)
add_executable(HalfFloatTest HalfFloatTest.cpp)
cm_example_project(HalfFloatTest)
add_executable(GetCpuInfo GetCpuInfo.cpp)
cm_example_project(GetCpuInfo)

View File

@ -1,21 +0,0 @@
#include<hgl/color/ColorFormat.h>
#include<iostream>
using namespace hgl;
using namespace std;
void half_float_test()
{
const float f_12_34 =12.34f;
const half_float hf_12_23=float2half(12.34f);
const float f_12_23_hf=half2float(hf_12_23);
cout<<"f_12_34="<<f_12_34<<endl;
cout<<"hf_12_23="<<hf_12_23<<endl;
cout<<"f_12_23_hf="<<f_12_23_hf<<endl;
}
void main(int,char **)
{
half_float_test();
}

61
HalfFloatTest.cpp Normal file
View File

@ -0,0 +1,61 @@
#include<hgl/math/HalfFloat.h>
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace hgl;
using namespace std;
static float origin_float[4];
void InitFloat4()
{
//随机产生4个f32浮点数
{
srand(time(nullptr));
uint8 *p=(uint8 *)origin_float;
for(uint i=0;i<16;i++)
p[i]=rand()%0xFF;
}
for(uint i=0;i<4;i++)
{
origin_float[i]=abs(origin_float[i]);
}
}
void OutputFloat4(const char *hint,const float *f)
{
cout<<hint<<" float4: "<<f[0]<<","<<f[1]<<","<<f[2]<<","<<f[3]<<endl;
}
void OutputHalfFloat(const char *hint,const half_float *hf)
{
cout<<hint<<" half_float: "<<hf[0]<<","<<hf[1]<<","<<hf[2]<<","<<hf[3]<<endl;
}
void half_float_test()
{
OutputFloat4("origin",origin_float);
half_float hf_fast[4];
half_float hf_std[4];
float_to_half(hf_fast,origin_float,4);
Float32toFloat16(hf_std,origin_float,4);
for(uint i=0;i<4;i++)
hf_std[i]&=0x7FFF; //去掉符号位
OutputHalfFloat("fast",hf_fast);
OutputHalfFloat("std ",hf_std);
}
void main(int,char **)
{
InitFloat4();
half_float_test();
}