octave-maintainers
[Top][All Lists]
Advanced

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

Re: A problem with range objects and floating point numbers


From: s.jo
Subject: Re: A problem with range objects and floating point numbers
Date: Tue, 23 Sep 2014 10:47:23 -0700 (PDT)

I am going to share the comparison results of colon operators in octave and
matlab.

* octave (3.8.2 on cygwin) vs matlab (R2012b on XP windows)

* test numbers: (-2:0.1:1)

* test methods: colon operator t1=(-2:0.1:1) vs t2=linspace(-2,1,31)

* output format: compare them with hexadecimal of raw IEEE bits.
[ num2str(t2','%5.2g'), repmat(' ',[numel(t1) 1]), num2hex(t1'), repmat('
',[numel(t1) 1]), num2hex(t2') ]

* result of octave: [index, colon oper, linspace ]


* result of matlab:



* conclusion: 
In matlab, the result of colon operator is very close to the result of the
linspace.
Note that all multiples of 0.5 have the exact floating point number. (which
has compact significant digits)
However, the result of colon operator in octave shows the poorest
performance: the values of -0.5, 0 and  0.5 do not show the exact floating
point representations.

The colon operation with floating-point numbers needs to improve, anyhow.
Or, the linspace function is preferable in Octave.

-- jo





--
View this message in context: 
http://octave.1599824.n4.nabble.com/A-problem-with-range-objects-and-floating-point-numbers-tp4664900p4666666.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.



reply via email to

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