フィルターのクリア

Why does legacy code scale variables by 2^16?

2 ビュー (過去 30 日間)
KAE
KAE 2017 年 11 月 20 日
編集済み: KAE 2017 年 11 月 22 日
I am trying to understand some legacy Matlab code, and was puzzled to note that many variables are multiplied or divided by 2^16. After some digging I found this is the largest number that a 16-bit (unsigned) integer can hold, see here. I believe the code originated in C or C#. I have two questions: (1) Could the code author be using this factor to force the variable to be a float? (2) If so, can I delete all the 2^16 factors without affecting the values in Matlab?
Here is an example,
SOME_THRESHOLD = floor(0.010 * 65536); % Author's comment indicates this is supposed to represent 10%
SOME_THRESHOLD gets passed in to a function which where all the other variables have been multiplied by either 65536 or 2^16 prior to arithmetic operations; floor and abs are also used.
  7 件のコメント
Image Analyst
Image Analyst 2017 年 11 月 21 日
I don't see the example in your original/edited question. But ... good luck though.
Christoph F.
Christoph F. 2017 年 11 月 22 日
I think the original author tried to make the MatLAB script use exactly the same numbers as the C code would.

サインインしてコメントする。

採用された回答

KAE
KAE 2017 年 11 月 22 日
編集済み: KAE 2017 年 11 月 22 日
Just to close this question out, based on all the comments and info at the links, it appears that the 2^16 factors are for binary scaling in the original C code. There could be numerical differences if the 2^16 factors were removed but they are small for my application. Thanks for all your help!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by