Skip to main content

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.

Timestamp model

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.

XML
<output><math:abs>-13.74</math:abs></output>
<!-- 13.74 -->

Full reference →


math:sign — Extract sign

Returns 1 (positive), 0 (zero), or -1 (negative).

XML
<output><math:sign>-13.74</math:sign></output>
<!-- -1 -->

Full reference →


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.

XML
<set var="number">1</set>
<math:inc var="number" />
<output>$number</output>
<!-- 2 -->

Full reference →


math:dec — Decrement variable

Decrements a variable in place by a given amount (default 1).

XML
<set var="number">2</set>
<math:dec var="number" />
<output>$number</output>
<!-- 1 -->

Full reference →


math:mod — Floating-point modulo

Returns the remainder of dividing x by y. Supports fractional values.

XML
<output><math:mod x="5.72" y="1.38" /></output>
<!-- 0.2 -->

Full reference →


Exponential and logarithmic functions

math:exp — Natural exponential

Raises Euler's number (e) to the given power.

XML
<output><math:exp>10</math:exp></output>
<!-- 22026.465794807 -->

Full reference →


math:ln — Natural logarithm

Computes the base-e logarithm. Input must be positive.

XML
<output><math:ln>22026.465794807</math:ln></output>
<!-- 10 -->

Full reference →


math:log — Logarithm with base

Computes the logarithm with a specified base (default 10).

XML
<output><math:log base="2">1024</math:log></output>
<!-- 10 -->

Full reference →


math:pow — Raise to power

Raises a value to the given exponent (default 2).

XML
<output><math:pow exponent="10">2</math:pow></output>
<!-- 1024 -->

Full reference →


math:sqrt — Square root

Returns the square root of a non-negative value.

XML
<output><math:sqrt>25</math:sqrt></output>
<!-- 5 -->

Full reference →


math:hypot — Hypotenuse

Computes sqrt(x^2 + y^2) with better numerical precision than doing it manually.

XML
<output><math:hypot x="3" y="5" /></output>
<!-- 5.8309518948453 -->

Full reference →


Constants

math:pi — Circle constant

Returns the mathematical constant pi with full floating-point precision.

XML
<output><math:pi /></output>
<!-- 3.1415926535898 -->

Full reference →


Trigonometric functions

All trigonometric functions operate in radians. Use math:convert to convert between degrees and radians.

Standard trigonometric functions

CommandDescription
math:sinSine of an angle
math:cosCosine of an angle
math:tanTangent of an angle
XML
<output><math:sin>1</math:sin></output>
<!-- 0.8414709848079 -->

math:sin reference → | math:cos reference → | math:tan reference →

Inverse (arc) functions

CommandDescription
math:asinArc sine — returns radians (input in [-1, 1])
math:acosArc cosine — returns radians (input in [-1, 1])
math:atanArc tangent — returns radians in (-pi/2, pi/2)
math:atan2Two-argument arc tangent — quadrant-aware, returns radians in (-pi, pi]
XML
<output><math:atan2 x="3" y="5" /></output>
<!-- 1.0303768265243 -->

math:asin | math:acos | math:atan | math:atan2

Hyperbolic functions

CommandDescription
math:sinhHyperbolic sine
math:coshHyperbolic cosine
math:tanhHyperbolic tangent
math:asinhInverse hyperbolic sine
math:acoshInverse hyperbolic cosine (input >= 1)
math:atanhInverse hyperbolic tangent (input in (-1, 1))
XML
<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).

XML
<output><math:round precision="2">17.213482971852</math:round></output>
<!-- 17.21 -->

For financial calculations, use half-even to minimize cumulative rounding error:

XML
<output><math:round precision="2" type="half-even">2.555</math:round></output>
<!-- 2.56 -->

Full reference →


math:ceil — Ceiling

Rounds a value up to the next highest integer.

XML
<output><math:ceil>17.213482971852</math:ceil></output>
<!-- 18 -->

Full reference →


math:floor — Floor

Rounds a value down to the next lowest integer.

XML
<output><math:floor>17.213482971852</math:floor></output>
<!-- 17 -->

Full reference →


Random numbers

math:rand — Generate random number

Generates a random integer. Optionally specify min and max for a range (inclusive).

XML
<set var="diceRoll"><math:rand min="1" max="6" /></set>
<output>You rolled: $diceRoll</output>

Full reference →


Number conversion

math:convert — Convert number representation

Converts between number bases and angular units. Supported representations: bin, oct, dec (default), hex, deg, rad.

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

XML
<output>
sin(45deg) = <math:sin><math:convert from="deg" to="rad">45</math:convert></math:sin>
</output>
<!-- sin(45deg) = 0.70710678118655 -->

Full reference →


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.

XML
<output><math:format countdec="2">1792702.213482971852</math:format></output>
<!-- 1,792,702.21 -->

German locale example:

XML
<output><math:format countdec="2" decpoint="," separator=".">1792702.213482971852</math:format></output>
<!-- 1.792.702,21 -->

Full reference →


Date and time

date:now — Current timestamp

Returns the current Unix timestamp. Use micro="true" for microsecond precision (returns a float).

XML
<date:now var="timestamp" />
<output>Current timestamp: $timestamp</output>

Full reference →


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.

XML
<date:info var="now" />
<output>Today is $now.year-$now.month-$now.day</output>

Supports the timezone attribute for time zone-aware decomposition:

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

Full reference →


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.

XML
<output><date:create day="1" month="1" year="2000" /></output>
<!-- 946684800 -->

Full reference →


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.

warning

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.

XML
<output><date:parse>2000-01-01</date:parse></output>
<!-- 946684800 -->

Full reference →


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:

CharOutputExample
Y4-digit year2025
mMonth (zero-padded)03
dDay (zero-padded)15
HHour 24h (zero-padded)14
iMinute (zero-padded)30
sSecond (zero-padded)00
cISO 8601 full2025-03-15T14:30:00+01:00
DDay name (3-letter)Sat
FMonth name (full)March
XML
<output><date:format format="Y-m-d">946684800</date:format></output>
<!-- 2000-01-01 -->

European format with time zone:

XML
<output><date:format format="d.m.Y H:i:s" timezone="Europe/Berlin">946684800</date:format></output>
<!-- 01.01.2000 01:00:00 -->
warning

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.

Full reference →