Ticket #106 (new defect)

Opened 2 years ago

Last modified 1 year ago

Max and min do not handle -0 right

Reported by: lth Assigned to: lth
Type: defect Priority: major
Milestone: M1 Component: RefImpl
Version: 4 Keywords:
Cc:

Description

Max and min are broken for -0, despite comments asserting they are not. Sort of hard to detect this in the current RI but I believe it to be true.

Attachments

Change History

Changed 1 year ago by lth

(Older comment culled from elsewhere.)

In ES3, -0 < 0 => false (11.8.5).

I believe IEEE specifies that behavior. If so, it would be a mistake to change it.

You can tell -0 from 0 by dividing 1 by the zero, -0 gives -Infinity and 0 gives Infinity, so if you know x is a zero the test for negative zero is (1/x < 0). In min the reasonable test would probably be

   y = Infinity;
   for ( x in args )  {
     if (isNaN(x))
       return x;
     if (x < y)
       y = x;
     else if (x === y && x === 0) {
       if (1/x < 0)
         y = x;  // pick up negative zero when appropriate
     }
   }
Note: See TracTickets for help on using tickets.