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 Comments

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

Sign in to comment.

Answers (1)

Adam
Adam on 22 Jul 2016
Edited: Adam on 22 Jul 2016
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.

Categories

Products

Asked:

on 22 Jul 2016

Edited:

on 22 Jul 2016

Community Treasure Hunt

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

Start Hunting!