Algosim documentation: number

number

Converts an object to a number.

Syntax

Description

If X is a number of any type, then number(X) returns X unaltered.

If X is a vector, matrix, list, set, or structure – in each case containing only a single element which is a number – then this number is returned in its natural data type.

If X is a string, then an attempt is made to parse it as a number. If successful, the parsed number is returned in the most specific data type possible: integer, rational number, real number, or complex number (in order of decreasing specificity).

In all other cases, number(X) returns an error.

Examples

number(❨❨9, 6, 5, 15❩❩ ⋅ ❨❨8❩, ❨12❩, ❨14❩, ❨12❩❩)
394
TestParse ≔ s ↦ '((x ≔ number(s)), type(x))
custom function
'("7", "39/4", "3.14159265E−2", "687 + 713j") @ TestParse
(7, integer)
(9.75, rational number)
(0.0314159265, real number)
(687 + 713⋅i, complex number)

See also