Closed Ragnar-F closed 9 months ago
Good catch! Of course the sorting callback return value is converted to an integer, so floats with a difference <1.0 were considered equal... This example code from Sort docs has the same issue:
MyVar := "5,3,7,9,1,13,999,-4"
MsgBox Sort(MyVar, "D,", IntegerSort)
IntegerSort(a1, a2, *)
{
return a1 - a2 ; Sorts in ascending numeric order. This method works only if the difference is never so large as to overflow a signed 64-bit integer.
}
This outputs -4,1,3,5,7,9,13,999
in ascending order as expected. However, replace the input string with 0.0,-0.08,-0.16,-0.34
and the result is 0.0,-0.08,-0.16,-0.34
, obviously incorrect.
I've pushed a fix for this, and also added a way to sort by Map keys (actually any object with __Item).
For the incorrect negative numerical sorting of array values, see the following example:
More a wish than a bug, but definitely useful: By replacing
fieldValue1.%key%
with(fieldValue1 is Map ? fieldValue1[key] : fieldValue1.%key%)
andfieldValue2.%key%
with(fieldValue2 is Map ? fieldValue2[key] : fieldValue2.%key%)
, the Key parameter also works for Map objects.