Re: List.sortBy shows wrong result
David Starner <[email protected]> Thu, 25 Feb 2016 08:36:57 +0000
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAMZ=zj68r8FMPyuSUcxPP+LORxX9OQL_PjpAjOwPLrk5JAL-3w@mail.gmail.com> |
The negation of -21474836848 in 32-bit two's complement arithmetic is -21474836848. There is no positive value corresponding to the negative of the minimal value in two's complement arithmetic. On Wed, Feb 24, 2016, 11:56 PM Chris <[email protected]> wrote: > Hi all, > > > List.sortBy show a strange behaviour: > > val l = List(Int.MinValue, Int.MinValue+1) > l.sortBy(I => I) // List(-2147483648, -2147483647) > l.sortBy(I => -I) // List(-2147483648, -2147483647) > > > If I use other values anything seems ok > > val l = List(Int.MinValue+2, Int.MinValue+1) > l.sortBy(I => I) // List(-2147483647, -2147483646) > l.sortBy(I => -I) // List(-2147483646, -2147483647) > > > What's wrong here? > Can anyone help? Thanks in advance. > > Chris > > > -- > You received this message because you are subscribed to the Google Groups > "scala-language" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.