フィルターのクリア

type conversion, precision loss

1 回表示 (過去 30 日間)
Stefan
Stefan 2014 年 1 月 6 日
回答済み: Walter Roberson 2014 年 1 月 6 日
I observed a strange behaviour when working with data read from a binary file. Here a small example:
>> a=int32(1);
>> b=12.5;
>> c=a+b
c =
14
The value of c is now 14 "instead" of 13.5. Why is (int32+double) silently typecasted to int32? Tried it with different matlab versions (2010, 2011, 2012, 2013) with the same result. So maybe I just don't understand the logic behind it? I guess I'd prefere a result without precision loss?

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 6 日
編集済み: Azzi Abdelmalek 2014 年 1 月 6 日
It's what Matlab do. I don't think, there is a logic behind it. If the result was double, you can ask the same question.
you can wrtie
a=int32(1);
b=12.5;
c=double(a)+b

Walter Roberson
Walter Roberson 2014 年 1 月 6 日

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by