Error in ceil() function?

조회 수: 8 (최근 30일)
Norbert Keimling
Norbert Keimling 2015년 11월 2일
편집: Stephen23 2015년 11월 2일
Hello,
Does anybody know why the ceil()-function Returns two different values in the following case?
X=[4 (1-0.95)*80]; ceil(X)
ans =
4 5
Thank you!

채택된 답변

Stephen23
Stephen23 2015년 11월 2일
편집: Stephen23 2015년 11월 2일
Floating point numbers are how decimal values are stored in your computer: they do not have infinite precision, and they can only approximate many values. Even if it looks like the "actual" value is being shown to you this does not mean that the internal representation inside your computer is the same value.
Lets have a quick look at those values:
>> X=[4 (1-0.95)*80]
X =
4.0000 4.0000
>> fprintf('%.30f\n',X)
4.000000000000000000000000000000
4.000000000000003552713678800501
It is not a problem with MATLAB, this is simply how (binary) computers work.
Read all about it:
And if you want to see what the decimal equivalent of a floating point value is, then try this FEX submission:
As its author points out: "Don't confuse the exact conversion with significance!"

추가 답변 (0개)

카테고리

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