MATLAB Answers

int2str returns the wrong result

조회 수: 7(최근 30일)
Kevin 2015년 7월 8일
댓글: Kevin 2015년 7월 8일
>> int2str(73167176531330624919225119674426574742355349194934)
ans =
Anyone know what's going on here? I'm guessing the number is too because when I evaluate the difference between the input and output, the answer is 0.
What causes Matlab to fill in nonsense numbers though?
  댓글 수: 1
Stephen Cobeldick
Stephen Cobeldick 2015년 7월 8일
double numbers, the default in MATLAB and many other programming languages, only support between 15 and 17 significant figures, the rest of those digits are meaningless.

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

채택된 답변

James Tursa
James Tursa 2015년 7월 8일
편집: James Tursa 2015년 7월 8일
Your original number has too many digits to store in a double precision number. E.g.,
ans =
So what you are seeing as output is exactly what is being stored (i.e., the exact decimal conversion of the binary bit pattern being stored), and there aren't enough mantissa bits in double precision to store more precision.
In fact, the nearest numbers in the double precision set to your original number are:
>> x = 73167176531330624919225119674426574742355349194934
>> num2strexact(x)
ans =
>> num2strexact(x+eps(x))
ans =
>> num2strexact(x-eps(x))
ans =
  댓글 수: 5
Kevin 2015년 7월 8일
Yes, I figured pasting into a file would probably be the proper thing to do but I was hoping there might be some shortcut.

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by