bugGNU Octave - Bugs: bug #51283, function min/max inconsistent...

 
 

bug #51283: function min/max inconsistent handling of -0

Submitted by:  Joel Dahne <urathai>
Submitted on:  Wed 21 Jun 2017 08:56:37 AM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: NoneAssigned to: None
Originator Name: JoelOpen/Closed: Open
Release: 4.2.1Operating System: GNU/Linux

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 08:54:47 PM UTC, comment #4:

The floating point values -0 and 0 must be considered equal and the max function may return either of them, see the maxNum function in IEEE Std 754-2008.

Also, the standard for floating point arithmetic says in chapter 11 (reproducible floating-point results) that users should write programs in such a way that they do not depend “on the sign of a zero result … for … maxNum (x, y) … when x and y are equal”.

Strictly speaking, Octave behaves well. However, I'd find it reasonable if Octave could return bit-equal results for the expressions max (x, y) and max ([x, y]). And it should be irrelevant whether x and y are scalars or vectors for choosing the first or second argument in cases where both are (semantically) equal.

Regarding the interval package: That should be fixed in the sine function. There already is a “l(l == 0) = -0;” for fixing the lower boundary. The upper boundary can equally be fixed with “u(u == 0) = +0;”. I have added these expressions in all cases where they could be needed, but obviously forgot it in sine.

For intervals, the lower boundary may not be stored as +0 internally. And the upper boundary may not be stored as -0 internally. This is enforced by the constructor. Many arithmetic operations use a shortcut and don't call the constructor, thus have to ensure this condition in the function file.

Oliver Heimlich <oheim>
Wed 21 Jun 2017 12:51:52 PM UTC, comment #3:

Matlab seems to always prefer the first one:
Though I'm not sure if this is intended or not, might just be that their code happens to check the arguments in the same order for scalars and vectors.

In most cases this of course makes no difference, the reason I noticed it is that in the interval package we have
and I were able to track it back to the max function.

Joel Dahne <urathai>
Wed 21 Jun 2017 12:49:09 PM UTC, comment #2:

Also, the behavior for -0 and 0 is supposed to be that the sign is ignored in comparisons, so -0 should compare equal to 0. That implies that it is neither less than nor greater 0. So I think for sorting, they should just be considered the same.

John W. Eaton <jwe>
Project Administrator
Wed 21 Jun 2017 12:43:34 PM UTC, comment #1:

Could someone check what Matlab does? It doesn't display the '-' for negative zero, but it can produce and preserve it. You can check for it by doing some other operation like x = -0; 1/x ==> -Inf.

So, for whoever wants to check this out, try some things like this:

John W. Eaton <jwe>
Project Administrator
Wed 21 Jun 2017 08:56:37 AM UTC, original submission:

The min/max functions does not seem to be aware of the difference between -0 and 0. We have (-0 == 0) = 1 and (-0 < 0) = 0, so it is not clear how to handle this case. The main problem however lies in that the result is different when comparing scalars versus when comparing vectors. For max we have
It looks like the function make no difference between -0 and 0, it probably just returns the first (or last?) of them it encounters. But as can be seen the order differs between scalars and vectors.

I think it would be more natural to return 0 in all cases, but at least be consistent with it.

Joel Dahne <urathai>

 

(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 oheim (Posted a comment)
  • -unavailable- added by jwe (Posted a comment)
  • -unavailable- added by urathai (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):

     

     

    No Changes Have Been Made to This Item

    Back to the top


    Powered by Savane 3.1-cleanup1