From bug-request at octave dot org Mon Oct 17 08:07:35 2005 Subject: Re: comparison error (approssimation?) From: Miroslaw Kwasniak To: bug at octave dot org Date: Mon, 17 Oct 2005 15:07:01 +0200 On Mon, Oct 17, 2005 at 03:48:54AM -0400, John W. Eaton wrote: > On 16-Oct-2005, Marco Iora wrote: > > | To: bug at octave dot org > | Cc: marcoiora > | Subject: comparison error (approssimation?) > | > | Bug report for Octave 2.1.71 configured for powerpc-apple-darwin7.9.0 > | > | Description: > | ----------- > | > | Octave does an uncorrectly comparison, i think due to approssimation. > | > | Repeat-By: > | --------- > | > | t = [-1:0.1:1] > | t(16) == 1/2 > | t(16) == 0.5 For Marco, see what Maxima says: a:0.1; b:1/10; c:a-b; [is(a=a), is(b=b), is(a=b), is(c=0)]; 0.1 1 -- 10 0.0 [TRUE, TRUE, FALSE, FALSE] ;) [...] > Here, cache is the matrix of values corresponding to range elements > (in some cases, the conversion to a matrix is not done). > > So how could this be improved? I though than doing increments in integers and scaling them is much better but this example: octave:1> n=1000;a=-1*n:.1:1*n; b=(-n*10:10*n)/10; ea=(diff(a)/.1)-1; eb=(diff(b)/.1)-1; octave:2> [ statistics (ea) statistics (eb)] ans = -9.0949e-13 -9.0949e-13 -5.6843e-14 -5.6843e-14 2.2737e-13 2.2737e-13 2.2737e-13 2.2737e-13 2.2737e-13 2.2737e-13 5.6821e-17 -2.2204e-20 <----------------- 3.5038e-13 3.5039e-13 -1.6464e+00 -1.6460e+00 1.6251e+00 1.6237e+00 shows only improvment in mean error. ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------