1.1 - int32(1) = 0 ?

조회 수: 2 (최근 30일)
Joel Stave
Joel Stave 2013년 7월 30일
The calculation: 1.1 - int32(1) results in 0. Some experimentation tells me that: 1.1 - double(int32(1)) results in the expected 0.1
I would have expected the combination of a double and an int32 to result in a double. Instead it appears to be an int32. Is this the defined behavior? Can anyone point me to a document showing data type precedence in Matlab.
Thanks

채택된 답변

James Tursa
James Tursa 2013년 7월 30일
편집: James Tursa 2013년 7월 30일
E.g., see here:
"Arithmetic operations that involve both integers and floating-point always result in an integer data type. MATLAB rounds the result, when necessary, according to the default rounding algorithm."
And, yes, this is not the way many other languages (e.g., Fortran, C/C++, etc) do this.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 7월 30일
http://www.mathworks.com/help/matlab/numeric-types.html when the operation is possible between two classes, I think the priority is for the class the less precise.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by