Hardcoded Integers in C code generated by Matlab Coder

x = A\B
was converted to C code using Matlab coder. There are few lines in the generated code with hard coded integers. Like..
if (rankR <= 1.4903363393874656E-8)
// Some internal function calls
else
// Usage of standard sqrt
or
500.0 * fabs(A[0]) * 2.2206044429501313E-16
What is the purpose of these hard coded integers ? How are they useful for left matrix division ?

댓글 수: 3

I would imagine they are 'epsilon' type parameters that are there to catch situations where you would end up dividing by zero or doing similarly ill-defined operations.
Adam, that should be an answer!
format long
>> eps
ans =
2.220446049250313e-16
>>
Done!

댓글을 달려면 로그인하십시오.

답변 (1개)

Adam
Adam 2016년 7월 22일
편집: Adam 2016년 7월 22일

0 개 추천

I would imagine they are 'epsilon' type parameters that are there to catch situations where you would end up dividing by zero or doing similarly ill-defined operations.
I've not seen the output of Matlab Coder myself yet though we do use it where I work, I just stay on the research end in Matlab itself personally.
By preference though I don't like seeing 'magic' numbers in code like that so I agree with your asking of the question because it is the type of question that magic numbers always throw up.
Nowadays I will always put a named constant in my file and use that instead.

카테고리

도움말 센터File Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

제품

질문:

2016년 7월 22일

편집:

2016년 7월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by