[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #42589] Inaccurate results with the colon oper
From: |
Julien Bect |
Subject: |
[Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator |
Date: |
Tue, 24 Jun 2014 06:44:16 +0000 |
User-agent: |
Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0 |
Follow-up Comment #27, bug #42589 (project octave):
> This is not really a bug, but if it's trivial to perform
> the computation in a way that matches Matlab's own
> error (there has to be an error, since there can't be
> exact representation), let's pick Matlab's error.
I still believe that this is a bug in Octave, not in Matlab.
I fully agree that 0.1 does NOT have an exact foating point representation.
But still 10 * 0.1 - 1 == 0 is true. However, 9 * 0.1 - 1 == -0.1 is false
(the result is 0.099999999...).
But please consider the following results and tell me if you still believe
that this is Octave (3.6.4) being right against all the others (Python 2.7.4,
R 3.1.0 and Matlab R2012a).
In R 3.1.0:
> 9 * 0.1 - 1 == 0.1
[1] FALSE
> 10 * 0.1 - 1 == 0.0
[1] TRUE
> x0 = c(-0.1, 0.0)
> x1 = c(9, 10) * 0.1 - 1
> x2 = seq (from = 9, to = 10, by = 1.0) * 0.1 - 1
> x1 == x0
[1] FALSE TRUE
> x2 == x0
[1] FALSE TRUE
In Python 2.7.4:
>>> 9 * .1 - 1 == - .1
False
>>> 10 * .1 - 1 == 0.0
True
>>> x0 = array ([-0.1, 0.0])
>>> x1 = arange (start = 9.0, stop = 11, step = 1.0) * 0.1 - 1
>>> x1 == x0
array([False, True], dtype=bool)
In Matlab R2012a:
>> format compact
>> 9 * 0.1 - 1 == -0.1
ans =
0
>> 10 * 0.1 - 1 == 0.0
ans =
1
>> x0 = [-0.1 0.0];
>> x1 = [9 10] * 0.1 - 1;
>> x2 = (9:10) * 0.1 - 1;
>> x1 == x0
ans =
0 1
>> x2 == x0
ans =
0 1
And finally in Octave 3.6.4:
octave:1> format short
octave:2> 9 * 0.1 - 1 == -0.1
ans = 0
octave:3> 10 * 0.1 - 1 == 0.0
ans = 1
octave:4> x0 = [-0.1 0.0];
octave:5> x1 = [9 10] * 0.1 - 1;
octave:6> x2 = (9:10) * 0.1 - 1;
octave:7> x1 == x0
ans =
0 1
octave:8> x2 == x0
ans =
0 0
Even the simple fact that x1 and x2 are not equal is very disturbing (perhaps
is it me again having a psychological issue ?). Correct me if I'm wrong but,
for a user of the Octave interpreter (not the C++ API), there is no such thing
as a "range object", so [9 10] and (9:10) should be the same, shouldn't they
?
octave:1> [9 10] == (9:10)
ans =
1 1
octave:2> [9 10] * 0.1 - 1 == (9:10) * 0.1 - 1
ans =
1 0
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?42589>
_______________________________________________
Message posté via/par Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, (continued)
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Rik, 2014/06/21
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Michael Godfrey, 2014/06/21
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Julien Bect, 2014/06/21
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Rik, 2014/06/21
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Julien Bect, 2014/06/22
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Michael Godfrey, 2014/06/22
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Rik, 2014/06/22
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Michael Godfrey, 2014/06/22
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Jordi Gutiérrez Hermoso, 2014/06/23
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Julien Bect, 2014/06/24
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator,
Julien Bect <=
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Rik, 2014/06/24
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Michael Godfrey, 2014/06/24
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, John W. Eaton, 2014/06/24
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Rik, 2014/06/24
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, John W. Eaton, 2014/06/24
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Rik, 2014/06/24
- [Octave-bug-tracker] [bug #42589] Inaccurate results with the colon operator, Rik, 2014/06/26