23.5.5 Converting strings to giac expressions
Using strings as commands.
The expr
command lets you use a string as a command.
-
expr takes
str, a string which expresses a valid command.
- expr(str) converts str to
the command and evaluates it.
Examples
a:="ifactor(54)":;
expr(a) |
which is the same thing as entering ifactor(54) directly.
Converting strings to numbers.
You can also use expr to convert a string to a number. If a
string is simply a number enclosed by quotation marks, then
expr will return the number.
Examples
The following strings will be converted to the
appropriate number.
A string consisting of the digits 0-9 which does not start
with 0 will be converted to an integer:
A string consisting of the digits 0-9 which contains a
single decimal point will be converted to a double:
A string consisting of the digits 0-9 and a single decimal point,
followed by e and then more digits,
will be read as a floating point number:
A string consisting of the digits 0-7 which starts
with 0 will be read as an integer base 8:
since 176 base 8 equals 126 base 10.
A string starting with 0x followed by digits 0-9
and letters A-F (or a-f) will be read as an integer
base 16:
since 2A3F base 16 equals 10815 base 10.
A string starting with 0b followed by digits 0 and 1 will
be read as a binary integer:
since 1101 base 2 equals 13 base 10.