Incorrect code generation by simulink
Show older comments
Hi,
I used a min library block in my model and the code generated for that used a fmin # define which was defined as below:
#define fminf(x,y) (x < y) ? x : y
This creates a problem when first argument is another fminf() statement. For example,
fminf(fminf(x, y), z)
The expanded form will look like this: ((x<y)?x:y<z)?(x<y)?x:y:z
This gives unexpected results.
If I update the #define as below, it works perfectly fine:
#define fminf(x,y) (((x) < (y)) ? (x) : (y))
Is this a bug? Is there a simulink option to say like "Do not generate code with ternary operator"?
Thank you.
Answers (0)
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!