numeric::sort
-- sort a numerical
listnumeric::sort
(list)
sorts the elements in
list
.
numeric::sort(list)
list |
- | a list of numbers or numerical expressions |
a sorted list
The function is sensitive to the environment variable DIGITS
.
float
. Elements that
cannot be converted lead to an error.numeric::eigenvalues
, numeric::eigenvectors
,
numeric::polyroots
,
numeric::singularvalues
and
numeric::singularvectors
.>> numeric::sort([1, 2.0, I, -3, -I, PI, sqrt(2)])
[-3.0, 1.0 I, - 1.0 I, 1.0, 1.414213562, 2.0, 3.141592654]
In the following example the sorting criterion does not seem to be satisfied:
>> x := sin(PI/3):
>> L := numeric::sort([x, sin(float(PI/3)) - I, x + I])
[0.8660254038 - 1.0 I, 0.8660254038, 0.8660254038 + 1.0 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 first element is indeed a little bit smaller than the other real parts:
>> DIGITS := 20: L
[0.86602540378443864668 - 1.0 I, 0.86602540378443864673, 0.86602540378443864673 + 1.0 I]
>> delete x, L, DIGITS: