fprintf('One number is %f\n', 436598989898987.124132)
조회 수: 3 (최근 30일)
이전 댓글 표시
I am wondering if someone can explain why after I input the command below:
fprintf('One number is %f\n', 436598989898987.124132)
The result I received was:
One number is 436598989898987.120000
I am curious about the difference between the two numbers.
Thank you in advance, - Lisa
댓글 수: 2
Cedric
2017년 9월 4일
편집: Cedric
2017년 9월 4일
Look at the eps documentation and then at these two cases:
fprintf('One number is %f\n', 436598989898987.124132 + eps( 436598989898987 ))
One number is 436598989898987.190000
fprintf('One number is %f\n', 436598989898987.124132 + eps( 436598989898987 )/2)
One number is 436598989898987.120000
If you want to see how the order of magnitude of the distance varies with the powers of 10
plot( 0:20, log10( eps( 10.^(0:20) ))) ;
grid ;
and you'll be able to find at 0 ( 10^0=1 ) the 2^-52 of the doc:
log10( 2^-52 )
ans =
-15.6536
Walter Roberson
2017년 9월 4일
>> eps(436598989898987.124132)
ans =
0.0625
Your number is only stored internally to within the nearest 0.0625
We can tell from the output that you are using MS Windows; on OS-X or Linux you would have gotten
One number is 436598989898987.125000
The MS Windows libraries are poor at formatting values exactly.
답변 (1개)
Mark Schwab
2017년 9월 7일
편집: Mark Schwab
2017년 9월 7일
The default data type for storing numbers in MATLAB is double. The double data type is a 64 bit data type that stores numbers in a representation similar to scientific notation. Within the 64 bits, one is reserved to specify sign (positive or negative). The next 11 bits are reserved for the exponent power and the remaining 52 bits are used for the fractional value. The number you are trying to store would require more than 52 bits to represent the fractional portion with exact precision so MATLAB uses floating point precision to round to a number it can represent in memory.
Please refer to the following documentation for more information: https://www.mathworks.com/help/matlab/matlab_prog/floating-point-numbers.html
참고 항목
카테고리
Help Center 및 File Exchange에서 Point Cloud Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!