Mathematics and Date/Time
The Math namespace provides arithmetic, trigonometry, rounding, random numbers, base conversion, and number formatting. The Date namespace provides Unix timestamp operations: retrieving, creating, decomposing, parsing, and formatting dates.
All date/time operations use Unix timestamps — seconds since January 1, 1970 00:00:00 UTC. There is no separate Date type; dates are always numeric timestamps.
Basic arithmetic
math:abs — Absolute value
Returns the non-negative magnitude of a number.
<output><math:abs>-13.74</math:abs></output>
<!-- 13.74 -->
math:sign — Extract sign
Returns 1 (positive), 0 (zero), or -1 (negative).
<output><math:sign>-13.74</math:sign></output>
<!-- -1 -->
math:inc — Increment variable
Increments a variable in place by a given amount (default 1). This is the idiomatic way to build counters in iXML.
<set var="number">1</set>
<math:inc var="number" />
<output>$number</output>
<!-- 2 -->
math:dec — Decrement variable
Decrements a variable in place by a given amount (default 1).
<set var="number">2</set>
<math:dec var="number" />
<output>$number</output>
<!-- 1 -->
math:mod — Floating-point modulo
Returns the remainder of dividing x by y. Supports fractional values.
<output><math:mod x="5.72" y="1.38" /></output>
<!-- 0.2 -->
Exponential and logarithmic functions
math:exp — Natural exponential
Raises Euler's number (e) to the given power.
<output><math:exp>10</math:exp></output>
<!-- 22026.465794807 -->
math:ln — Natural logarithm
Computes the base-e logarithm. Input must be positive.
<output><math:ln>22026.465794807</math:ln></output>
<!-- 10 -->
math:log — Logarithm with base
Computes the logarithm with a specified base (default 10).
<output><math:log base="2">1024</math:log></output>
<!-- 10 -->
math:pow — Raise to power
Raises a value to the given exponent (default 2).
<output><math:pow exponent="10">2</math:pow></output>
<!-- 1024 -->
math:sqrt — Square root
Returns the square root of a non-negative value.
<output><math:sqrt>25</math:sqrt></output>
<!-- 5 -->
math:hypot — Hypotenuse
Computes sqrt(x^2 + y^2) with better numerical precision than doing it manually.
<output><math:hypot x="3" y="5" /></output>
<!-- 5.8309518948453 -->
Constants
math:pi — Circle constant
Returns the mathematical constant pi with full floating-point precision.
<output><math:pi /></output>
<!-- 3.1415926535898 -->
Trigonometric functions
All trigonometric functions operate in radians. Use math:convert to convert between degrees and radians.
Standard trigonometric functions
| Command | Description |
|---|---|
math:sin | Sine of an angle |
math:cos | Cosine of an angle |
math:tan | Tangent of an angle |
<output><math:sin>1</math:sin></output>
<!-- 0.8414709848079 -->
math:sin reference → | math:cos reference → | math:tan reference →
Inverse (arc) functions
| Command | Description |
|---|---|
math:asin | Arc sine — returns radians (input in [-1, 1]) |
math:acos | Arc cosine — returns radians (input in [-1, 1]) |
math:atan | Arc tangent — returns radians in (-pi/2, pi/2) |
math:atan2 | Two-argument arc tangent — quadrant-aware, returns radians in (-pi, pi] |
<output><math:atan2 x="3" y="5" /></output>
<!-- 1.0303768265243 -->
math:asin → | math:acos → | math:atan → | math:atan2 →
Hyperbolic functions
| Command | Description |
|---|---|
math:sinh | Hyperbolic sine |
math:cosh | Hyperbolic cosine |
math:tanh | Hyperbolic tangent |
math:asinh | Inverse hyperbolic sine |
math:acosh | Inverse hyperbolic cosine (input >= 1) |
math:atanh | Inverse hyperbolic tangent (input in (-1, 1)) |
<output><math:sinh>1</math:sinh></output>
<!-- 1.1752011936438 -->
math:sinh → | math:cosh → | math:tanh → | math:asinh → | math:acosh → | math:atanh →
Rounding
math:round — Round to precision
Rounds a value to a specified number of decimal places. Supports 10 rounding strategies via the type attribute. Default mode is half-infinity (ties round away from zero).
Nearest-value modes: half-infinity (default), half-zero, half-up, half-down, half-even (banker's rounding), half-odd.
Directed modes: infinity (away from zero), zero (truncate), up (ceiling), down (floor).
<output><math:round precision="2">17.213482971852</math:round></output>
<!-- 17.21 -->
For financial calculations, use half-even to minimize cumulative rounding error:
<output><math:round precision="2" type="half-even">2.555</math:round></output>
<!-- 2.56 -->
math:ceil — Ceiling
Rounds a value up to the next highest integer.
<output><math:ceil>17.213482971852</math:ceil></output>
<!-- 18 -->
math:floor — Floor
Rounds a value down to the next lowest integer.
<output><math:floor>17.213482971852</math:floor></output>
<!-- 17 -->
Random numbers
math:rand — Generate random number
Generates a random integer. Optionally specify min and max for a range (inclusive).
<set var="diceRoll"><math:rand min="1" max="6" /></set>
<output>You rolled: $diceRoll</output>
Number conversion
math:convert — Convert number representation
Converts between number bases and angular units. Supported representations: bin, oct, dec (default), hex, deg, rad.
<!-- Hex to binary -->
<output><math:convert from="hex" to="bin">7cd5a72c</math:convert></output>
<!-- 1111100110101011010011100101100 -->
Particularly useful for converting degrees to radians before trigonometric operations:
<output>
sin(45deg) = <math:sin><math:convert from="deg" to="rad">45</math:convert></math:sin>
</output>
<!-- sin(45deg) = 0.70710678118655 -->
Number formatting
math:format — Format number for display
Produces a display string with fixed decimal places, configurable decimal point (decpoint), and thousands separator (separator). Returns a string, not a number -- do not use the result in further arithmetic.
<output><math:format countdec="2">1792702.213482971852</math:format></output>
<!-- 1,792,702.21 -->
German locale example:
<output><math:format countdec="2" decpoint="," separator=".">1792702.213482971852</math:format></output>
<!-- 1.792.702,21 -->
Date and time
date:now — Current timestamp
Returns the current Unix timestamp. Use micro="true" for microsecond precision (returns a float).
<date:now var="timestamp" />
<output>Current timestamp: $timestamp</output>
date:info — Decompose timestamp
Breaks a timestamp into components: day, month, year, hour, minute, second, wday (0=Sunday..6=Saturday), yday. If no timestamp given, uses the current time.
<date:info var="now" />
<output>Today is $now.year-$now.month-$now.day</output>
Supports the timezone attribute for time zone-aware decomposition:
<date:info var="berlin" timezone="Europe/Berlin">946684800</date:info>
<output>In Berlin: $berlin.year-$berlin.month-$berlin.day $berlin.hour:$berlin.minute</output>
<!-- In Berlin: 2000-1-1 1:0 -->
date:create — Create timestamp from components
Constructs a Unix timestamp from day, month, year (required) and optionally hour, minute, second, timezone. Returns NULL for invalid dates.
<output><date:create day="1" month="1" year="2000" /></output>
<!-- 946684800 -->
date:parse — Parse date string
Converts a date string into a Unix timestamp. Accepts ISO 8601, common formats, and relative expressions. Returns NULL if unparseable. Use timezone to set the assumed time zone for strings without explicit zone info.
Always verify parsed results. Ambiguous formats (e.g., 01/02/2025 -- is that Jan 2 or Feb 1?) may not parse as expected. Prefer ISO 8601 (YYYY-MM-DD) when possible.
<output><date:parse>2000-01-01</date:parse></output>
<!-- 946684800 -->
date:format — Format timestamp
Converts a timestamp to a string using PHP-compatible format characters. If no timestamp given, uses the current time. Default format is c (ISO 8601).
Common format characters:
| Char | Output | Example |
|---|---|---|
Y | 4-digit year | 2025 |
m | Month (zero-padded) | 03 |
d | Day (zero-padded) | 15 |
H | Hour 24h (zero-padded) | 14 |
i | Minute (zero-padded) | 30 |
s | Second (zero-padded) | 00 |
c | ISO 8601 full | 2025-03-15T14:30:00+01:00 |
D | Day name (3-letter) | Sat |
F | Month name (full) | March |
<output><date:format format="Y-m-d">946684800</date:format></output>
<!-- 2000-01-01 -->
European format with time zone:
<output><date:format format="d.m.Y H:i:s" timezone="Europe/Berlin">946684800</date:format></output>
<!-- 01.01.2000 01:00:00 -->
Literal characters matching format codes must be backslash-escaped. For example, \a\t produces the text "at", not the a (am/pm) and t (days in month) format codes.