## `numeric::sort` -- sort a numerical list

#### Introduction

`numeric::sort``(list)` sorts the elements in `list`.

#### Call(s)

`numeric::sort(list)`

#### Parameters

`list` | - | a list of numbers or numerical expressions

#### Returns

a sorted list

#### Side Effects

The function is sensitive to the environment variable `DIGITS`.

#### Related Functions

`sort`

#### Details

- The elements of the list are converted to floating point numbers via `float`. Elements that cannot be converted lead to an error.
- The floating point numbers are sorted from small real part to large real part. Elements with the same real part are sorted from small absolute value to large absolute value. In case of a tie (i.e., two elements form a complex conjugate pair) the element with positive imaginary part comes first.
- This function is used to sort the return values of `numeric::eigenvalues`, `numeric::eigenvectors`, `numeric::polyroots`, `numeric::singularvalues` and `numeric::singularvectors`.

#### Example 1

    >> 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:

#### Changes

- new function

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000