help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Exact zero


From: Allen.Windhorn
Subject: RE: Exact zero
Date: Fri, 27 May 2011 14:58:41 -0500

 

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of Martin Helm

Am Freitag, 27. Mai 2011, 20:58:20 schrieb Martin Helm:
> Am Freitag, 27. Mai 2011, 20:43:38 schrieb Patrick Carle:
> > This prints a list of numbers, one of which is exactly zero :
> > 
> > fprintf('%.1e\n',((3:14)-14/2)*.01);
> > 
> > But when the 3 is changed to a 2 in ie:
> > 
> > fprintf('%.1e\n',((2:14)-14/2)*.01);
> > 
> > The number that used to be exactly zero is now -1.7e-018. Is this a
bug?
> > Is there a way to force this to be exactly zero?

Try this (I've done some formatting):

octave-3.2.4.exe:9> format long g
octave-3.2.4.exe:9> A=2:14
A =

2 3 4 5 6 7 8 9 10 11 12 13 14  % All integers as far as I can see

octave-3.2.4.exe:10> A(6)-14/2
ans =                    0      % Appears to be exact

octave-3.2.4.exe:13> B = A.-14/2
B =

-5 -4 -3 -2 -1 0 1 2 3 4 5 6 7

octave-3.2.4.exe:9> B(6)
ans =                    0      % Still exact?

octave-3.2.4.exe:14> B*0.01
ans =

 Columns 1 through 4:

 -0.05 -0.04 -0.03 -0.02

 Columns 5 through 8:

 -0.01  -1.73472347597681e-018 0.01 0.02

 Columns 9 through 12:

 0.03 0.04 0.05 0.06

 Column 13:

 0.07

octave-3.2.4.exe:17> B(6)*0.01
ans =                    0

octave-3.2.4.exe:18> B.*0.01
ans =

 Columns 1 through 4:

-0.05 -0.04 -0.03 -0.02

 Columns 5 through 8:

-0.01 0 0.01 0.02

 Columns 9 through 12:

 0.03 0.04 0.05 0.06

 Column 13:

 0.07

Something funny going on here with matrix vs. element multiplication.

Allen


reply via email to

[Prev in Thread] Current Thread [Next in Thread]