matlab interp C code generation, Waring: comparing floating point with == or != is unsafe
조회 수: 14(최근 30일)
I use interp1,interp2 in a .m file and generate C code, then the _sharedutils folder has a new xxxxx_interp1.c file to realize interp function, but the generated C code use "if floating point == floating point ", so C complier warn: comparing floating point with == or != is unsafe, how can I solve the problem in matlab and let it generate the rigtht C code.
SlipperyGnome 2022년 6월 23일
Hi da wu,
When comparing floating point numbers, because of very small rounding off errors, using '==' or '!=' will generate compiler warnings.
You can set an error tolerance upto the magnitude you need it to be same.
if (abs(num1-num2) < Error_tolerance)
This tolerance value method would work accurately upto 1e-15. You can also go to this link for better understanding.