Re: List.sortBy shows wrong result

Chris <[email protected]> Thu, 25 Feb 2016 03:52:03 -0800 (PST)
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
Oh! Yes. Now it's clear.

Many thanks for your help
Chris


Am Donnerstag, 25. Februar 2016 11:30:05 UTC+1 schrieb Jasper-M:
>
> Because, in the case of
> l.sortBy(I => -I) // List(-2147483648, -2147483647)
> the list will be sorted by applying the function I => -I to every element, 
> sorting the resulting list, and then unapplying the function again (well, 
> that's not really what happens, but you can think of it that way...).
> So: -(-2147483648) == -2147483648
>     -(-2147483647) == 2147483647
>     -2147483648 < 2147483647
>
> Op donderdag 25 februari 2016 10:06:46 UTC+1 schreef Chris:
>>
>> Yes, but why does this affect the sort order?
>>
>>
>>
>> Am Donnerstag, 25. Februar 2016 09:37:10 UTC+1 schrieb David Starner:
>>>
>>> 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.