Skip to main content

Numbers

iXML supports two numeric types:

  1. Integer (int) — whole numbers without a fractional part.
  2. 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:

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

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

BasePrefixExampleDecimal
Decimal (base 10)none123123
Hexadecimal (base 16)0x0x1A26
Octal (base 8)001715
Binary (base 2)0b0b110113

Floating point numbers support decimal and scientific E notation (1.5e3 = 1500.0, 2.5e-2 = 0.025).

warning

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:

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

XML
<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.