Non-Confidential | PDF version | ARM DUI0840C | ||

| ||||

Home > Introduction to MxScript > Syntax conventions of MxScript > Expressions |

An expression consists of constants, variables, and function
calls that are combined with operators.

Parentheses can be used to group expressions to alter the
evaluation sequence from that defined by the precedence:

3 * (4 + 7)

Unlike in C, there is no automatic type casting in MxScript. The expression

```
(3.14 *
2)
```

causes an error because `double`

and `int`

types
are mixed. Both C and C++ forms of casts are permitted. A string can be multiplied by an integer to create a concatenated
string:

`“hello” * 2`

is equivalent to`“hellohello”`

.`4 * “#”`

is equivalent to`“####”`

.

String/integer casts are permitted:

`(string)5`

is equivalent to`"5"`

.`string(5 + 77)`

is equivalent to`"82"`

.`int("555")`

is equivalent to`555`

.`(int)("0b" + "111")`

is equivalent to`7`

.`int("xfff")`

is equivalent to`0`

because the string does not start with`0`

.`int("255xfff")`

is equivalent to`255`

because the non-numbers are ignored.

**Table 1-4 Results of cast operations**

Original type | Casting to int | Casting to string | Casting to bool | Casting to double |
---|---|---|---|---|

`int` |
Error. | Convert to string containing decimal integer format. | `false` if integer is 0, otherwise `true` . |
Convert to double with same value. |

`string` |
Interpret string as integer number. Prefixes `0b` (binary),
`0x` (hexadecimal) and `0` (octal) are
recognized. |
Error. | Error. | Interpret string as a decimal floating-point number in C format. |

`bool` |
1 if `true` , 0 if `false` . |
`“true”` if `true` , `“false”` if `false` . |
Error. | Error. |

`double` |
Round down to a lower integer value. Same as `floor()` function
in C. |
Convert to string containing decimal floating-point format. | Error. | Error. |