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 个评论
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.
Sean de Wolski
2016-7-22
Adam, that should be an answer!
format long
>> eps
ans =
2.220446049250313e-16
>>
Adam
2016-7-22
Done!
回答(1 个)
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 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!