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: Mon, 29 Sep 2014 18:36:06 -0700 (PDT)

John W. Eaton wrote
> Does it also bother you that the results of the following two 
> expressions are not exactly bit for bit identical?
> 
>    linspace (-20, 1, 22) * .1
>    linspace (-2, .1, 22)
> 
> This is exactly the sort of thing you are comparing, and with binary 
> representation of decimal numbers, I don't see a solution that will give 
> you the results you seem to want in all cases.  That's just the nature 
> of doing binary floating point operations.
> 
> I don't think Matlab gives the same results for these expressions 
> either, so compatibility isn't an argument for changing Octave's 
> behavior here.
> 
> I plan to add an option to Octave (enabled by default when using the 
> --traditional option) that will cause Octave's range operator to create 
> a matrix immediately rather than storing just the base, limit, increment 
> (and sometimes number of elements).  That way the two expressions
> 
>    (-20:1:1) * .1
>    [-20:1:1] * .1
> 
> will produce the same values, because the range will be expanded 
> immediately into a matrix in both cases.
> 
> jwe

Thanks to Dan's script, I can see when the range type is changed into the
matrix type.
Note that  (-20:1:1) * .1 and (-2:0.1:0.1) are same in binary format.

I agree jwe's idea:  when we use a script of range multiplied with
floating-point number 
such as (-20:1:1) * .1 , we expect a row vector that might be used for some
numerical test.
Range object is not necessarily retained.

However, the range with operated with integer such as (-20:1:1) *2+1 should
be 
supported in range object.
I guess that such operations can be handled by matrix index, or any other
integer related algorithm.
The condensed range object has much benefit on that application.

My idea is that any range operated with floating-point numbers should be
stored in matrix class.
But ranges operated with integer numbers should remain in range object.
Based on that idea, range operation does not need to add option for matrix
storage.

-- jo






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



reply via email to

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