About floor function problem.

8 ビュー (過去 30 日間)
C Zeng
C Zeng 2012 年 10 月 23 日
floor(1.999999999999)=1 floor(1.99999999999999999999999999)=2, why is that?
Floor should return the lower integer right? Thanks.

採用された回答

Matt J
Matt J 2012 年 10 月 23 日
編集済み: Matt J 2012 年 10 月 23 日
If that confuses you, this probably will too:
>> isequal(1.99999999999999999999999999, 2)
ans =
1
Anyway, it has nothing to do with the FLOOR command. It's because your big long decimal can't be distinguished from 2 in floating point.
  6 件のコメント
Matt J
Matt J 2012 年 10 月 23 日
What was your "previous question"?
Matt J
Matt J 2012 年 10 月 23 日
This one contains an overloaded floor function, if that's what you mean

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 10 月 23 日
Just try without floor
a=1.99999999999999999999999999
  8 件のコメント
Walter Roberson
Walter Roberson 2012 年 10 月 23 日
If you are starting with an integer, then dividing by a power of 2 can never result in this kind of round-off. Powers of 2 are represented exactly in binary floating point numbers, and dividing by a power of two effectively only changes the internal binary exponent without changing the mantissa. If you are running into this kind of round-off then either you are not starting with an integer or you are not dividing by a power of 2.
C Zeng
C Zeng 2012 年 10 月 26 日
Thanks, Walter, though I do not understand your point. I am transferring an integer like N to 2-digits. I want to divide it by 2 to determine if the entry is 0 or 1. Floor function does not make sufficient proximity to this problem.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by