WHY -1 IS USED IN THE BLOCKS FOR INHERITING SAMPLETIME

1 回表示 (過去 30 日間)
prashanna kumar
prashanna kumar 2022 年 10 月 31 日
回答済み: Walter Roberson 2022 年 10 月 31 日
-1 IS USED FOR INHERTING THE SAMPLE TIME OF PREVIOUS BLOCK AND WHY -1 IS USED TO DEFINE THAT

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 10 月 31 日
Sample times are stored as double precision numbers. Any finite positive double precision number might be a valid sample time.
The possible representations for "inherited" are thus limited to 0, negative numbers, or the non-finite values +inf, -inf, or nan. 0 is, though used for other purposes (involving discrete time) so the choices became a negative number or a non-finite number.
Of these possibilities, the shortest to write are -1 through -9, at two characters each, whereas inf and nan need three and -inf needs four characters. Furthermore, in many instructions there is a separate internal path for processing nan so nan is slower than finite values. For example you cannot use "if sampletime == nan" because nan has a special path for all relational operations that say that the results of a test involving nan are always false.
So for simplicity and performance, the choices were -1 through -9. And there was no particular reason to choose anything other than -1 (which is arguably also the easiest for users to remember.)
If I recall correctly, -2 and -3 are also used internally for some purposes.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by