# How to improve double precision?

조회 수: 4 (최근 30일)
NoYeah 2020년 7월 23일
편집: Stephen23 2020년 7월 25일
a=11;
b=256;
c=a/b
and the output said c=0, which was not I had expected
So I have used cast operator
a=11;
b=256;
c=double(a/b)
and the result returns the same value; 0
I have searched Matlab document and found that the default precision of double data type is 32
so It should return 0.04296875 instead of 0. But still get 0 for this kind of codes
How to fix it properly?
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
dpb 2020년 7월 23일
I asked you to type in teh above commands on your system and tell us what you get?
Stephen23 2020년 7월 23일
편집: Stephen23 2020년 7월 25일
"I have searched Matlab document and found that the default precision of double data type is 32"
Highly unlikely. Can you please provide a link to the MATLAB documentation where this value comes from?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Walter Roberson 2020년 7월 23일
Either your a or your b is type uint8. When you work with int8, int16, int32, uint8, uint16, or uint32, then the operands are converted to double(), and the operation is done, and then the result is converted back to the most restricted type used.
Operations for int64 and uint64 are handled differently in some, because 64 bit integers cannot be converted to double without losing precision.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
dpb 2020년 7월 23일
편집: dpb 2020년 7월 23일
Could be any of the int classes, of course...what the
whos a b c
would have told us is which one(s) OP had...what OP didn't show was how a, b were created to begin with to become int class

댓글을 달려면 로그인하십시오.

### 카테고리

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