Incorrect code generation by simulink

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

Products

Release

R2018b

Asked:

on 28 Oct 2021

Community Treasure Hunt

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

Start Hunting!