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.

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

製品

リリース

R2018b

質問済み:

2021 年 10 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by