Sort a numerical list
This functionality does not run in MATLAB.
numeric::sort(list) sorts the elements in list.
The elements of the list are sorted such that their real parts are descending. Elements with the same real part are sorted from large absolute value to small absolute value. In case of a tie (i.e., two elements form a complex conjugate pair), the element with positive imaginary part comes first.
The elements of the list are converted to floating-point numbers via float. Elements that cannot be converted lead to an error.
The function is sensitive to the environment variable DIGITS.
The elements in the sorted list have descending real parts:
numeric::sort([1, 2.0, I, -3, -I, PI, sqrt(2)])
In the following example, the sorting criterion does not seem to be satisfied. Elements with the same real part are supposed to be ordered from large absolute values to small absolute values:
x := sin(PI/3): L := numeric::sort([x, sin(float(PI/3)) - I, x + I])
This is explained by the fact that the floating-point numbers internally have a more accurate representation than shown on the screen. The real part of the last element is indeed a little bit smaller than the other real parts:
DIGITS := 20: L
delete x, L, DIGITS: