bugGNU Octave - Bugs: bug #51282, Column vector and equality...

 
 

bug #51282: Column vector and equality operator are not playing nice together.

Submitter:  None
Submitted:  Tue 20 Jun 2017 11:41:58 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  Nathan Howard Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.1
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 21 Jun 2017 05:02:15 AM UTC, comment #4: 

Ok.  I also checked the manual, and even though it states, "A range is a convenient way to write a row vector with evenly spaced elements," it does make note (further down) concerning the practical behavior.

It's interesting that using square brackets gives you a hint that something's not copacetic (at least in the example sent) say p = [-1:.1:1] shows the center element as something other than zero.

It'd be nice if the implementation details weren't such a required knowledge for doing the Math-business end of it... but I'm likely beating a dead horse, so I'll leave this topic for now.

I appreciate the time spent.  Thank you.

N Howard <adanhawthorn>
Wed 21 Jun 2017 02:42:15 AM UTC, comment #3: 

What you want to ask Octave for is


d = (-10:10)./10;


What you are asking Octave for is to add multiples of 0.1 to a starting value of -1 until it hits +1.

If you do understand floating point representation, which jwe provided a pointer for, then you'll know why the following relationship returns false:


>> -1 + 0.1 * 6
ans = -0.40000
>> -1 + 0.1 * 6 == -0.4
ans = 0


That should be enough to explain why the computed range you asked for is behaving the way it is.

Mike Miller <mtmiller>
Group Member
Wed 21 Jun 2017 01:19:09 AM UTC, comment #2: 

Thank you for the quick reply.  Perhaps we can drill a little further with this?  What I'm looking for is:

d = (-1:.1:1);

that is, one decimal point of precision, but instead, it seems that Octave is running far deeper than that.  For instance, if I were to do:

>> r = 0.3999999999999999

r =  0.400000000000000

then that would follow, but if I were to simply instead:

>> r = 0.399

r =  0.399000000000000

>> e = 0.399

e =  0.399000000000000

>> r == e

ans = 1

then life is happy again.  It appears as though d is generated in a manner that doesn't honor my ask; if it would, then my simple equality would hold without trouble.  For instance,

d_better = [-1 -.9 -.8 -.7 -.6 -.5 -.4 -.3 -.2 -.1 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1];

>> d_better == d

ans =

  1  1  1  1  1  1  0  0  0  0  0  0  0  0  0  0  0  0  1  0  1
 
but this should hold if d was generated as asked for; therefore, the generated d is not a good representation of what was sought.

As far as I can tell, this would be a bug.

N Howard <adanhawthorn>
Tue 20 Jun 2017 11:57:11 PM UTC, comment #1: 

This is not a bug.  Please see:

http://wiki.octave.org/FAQ#Why_is_this_floating_point_computation_wrong.3F

Also, the "format" function just affects display, not computation.

John W. Eaton <jwe>
Group administrator
Tue 20 Jun 2017 11:41:58 PM UTC, original submission:  

It looks like the equality operator is picking up a rounding error issue when using a column vector, such that:

>> d = (-1:.1:1);
>> sum(d==-0.5)

ans =  1

>> sum(d==-0.4)

ans = 0

>> sum(d==-0.39999999999999999)

ans =  1

>> sum(d==-0.3999999999999999)

ans = 0

This happens in both format short and long modes.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by adanhawthorn (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-06-20 jwe StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code