Numbers
iXML supports two numeric types:
- Integer (
int) — whole numbers without a fractional part. - Float (
float) — numbers with a fractional part.
Neutral literals
- Integer:
0 - Float:
0.0
Creating numbers
Remember that <set> always creates strings. To create actual numeric values, use cast:
<set var="x">42</set> <!-- string "42" -->
<cast var="x" type="int" /> <!-- integer 42 -->
<set var="y">3.14</set> <!-- string "3.14" -->
<cast var="y" type="float" /> <!-- float 3.14 -->
Automatic arithmetic evaluation
Whenever a number is explicitly expected (attributes of type int or float), the corresponding expression is automatically evaluated arithmetically. You can write expressions directly in these attribute values:
<for var="i" from="2 * 3" to="(10 + 5) / 3">
<output>$i </output>
</for>
<!-- 6 5 4 -->
Number notation
Integer numbers can be specified in multiple bases:
| Base | Prefix | Example | Decimal |
|---|---|---|---|
| Decimal (base 10) | none | 123 | 123 |
| Hexadecimal (base 16) | 0x | 0x1A | 26 |
| Octal (base 8) | 0 | 017 | 15 |
| Binary (base 2) | 0b | 0b1101 | 13 |
Floating point numbers support decimal and scientific E notation (1.5e3 = 1500.0, 2.5e-2 = 0.025).
The octal prefix 0 can cause unexpected results. 010 is octal 10 = decimal 8. Use bare decimal notation to avoid this ambiguity.
Inline arithmetic
The $() syntax embeds arithmetic results into string context:
<set var="birthyear">1950</set>
<output>This person is $(2025 - $birthyear) years old!</output>
<!-- This person is 75 years old! -->
Numeric comparison
When both sides of an <if> comparison look numeric, iXML performs numeric comparison:
<if value1="0" func="=" value2="0.0">
<output>These are numerically equal</output>
</if>
See Type Conversion for the full comparison behavior table.
Math operations
For advanced math operations (abs, rounding, trigonometry, random, etc.), see the Standard Library: Math & DateTime chapter.