About floor function problem.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
floor(1.999999999999)=1 floor(1.99999999999999999999999999)=2, why is that?
Floor should return the lower integer right? Thanks.
0 commentaires
Réponse acceptée
Matt J
le 23 Oct 2012
Modifié(e) : Matt J
le 23 Oct 2012
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 commentaires
Matt J
le 23 Oct 2012
This one contains an overloaded floor function, if that's what you mean
Plus de réponses (1)
Azzi Abdelmalek
le 23 Oct 2012
Just try without floor
a=1.99999999999999999999999999
8 commentaires
Walter Roberson
le 23 Oct 2012
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.
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!