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: John W. Eaton
Subject: Re: A problem with range objects and floating point numbers
Date: Mon, 29 Sep 2014 13:51:41 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.5.0

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




reply via email to

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