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

 
 

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

Submitted by:  None
Submitted on:  Tue 20 Jun 2017 11:41:58 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Inaccurate Result
Status: InvalidAssigned to: None
Originator Name: Nathan HowardOriginator Email: -unavailable-
Open/Closed: ClosedRelease: 4.2.1
Operating System: Microsoft Windows

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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

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:

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

Mike Miller <mtmiller>
Project Administrator
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>
Project 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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 20 Jun 2017 11:57:11 PM UTCjweStatusNone=>Invalid
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1