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
>>

请先登录,再进行评论。

回答(1 个)

Adam
Adam 2016-7-22
编辑:Adam 2016-7-22
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