> For the complete documentation index, see [llms.txt](https://php-fhir-tools.ardenexal.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://php-fhir-tools.ardenexal.net/fhirpath/functions/math.md).

# Math

Math functions operate on numeric values. Single-value functions (`abs()`, `ceiling()`, etc.) expect a single-item numeric input; aggregate functions (`sum()`, `min()`, `max()`, `avg()`) operate over the whole collection.

| Function             | Description                                               | Example                       |
| -------------------- | --------------------------------------------------------- | ----------------------------- |
| `sum()`              | Sum of all numeric items in the collection.               | `(1 \| 2 \| 3).sum()` → `6`   |
| `abs()`              | Absolute value.                                           | `(-5).abs()` → `5`            |
| `ceiling()`          | Smallest integer greater than or equal to the input.      | `(1.1).ceiling()` → `2`       |
| `floor()`            | Largest integer less than or equal to the input.          | `(1.9).floor()` → `1`         |
| `truncate()`         | Integer part, dropping any fraction.                      | `(1.9).truncate()` → `1`      |
| `round([precision])` | Rounds to the given number of decimal places (default 0). | `(3.14159).round(2)` → `3.14` |
| `exp()`              | e raised to the power of the input.                       | `(1).exp()` → `2.718...`      |
| `ln()`               | Natural logarithm.                                        | `(2.718281828).ln()` → `1.0`  |
| `log(base)`          | Logarithm to the given base.                              | `(100).log(10)` → `2`         |
| `power(exponent)`    | Raises the input to `exponent`.                           | `(2).power(3)` → `8`          |
| `sqrt()`             | Square root.                                              | `(9).sqrt()` → `3`            |
| `min()`              | Smallest item in the collection.                          | `(3 \| 1 \| 2).min()` → `1`   |
| `max()`              | Largest item in the collection.                           | `(3 \| 1 \| 2).max()` → `3`   |
| `avg()`              | Arithmetic mean of the collection.                        | `(2 \| 4 \| 6).avg()` → `4`   |

## Precision & boundaries

These three functions report or derive the precision of a value. They accept a decimal, integer, date, dateTime, or time, using FHIRPath positional precision numbers (e.g. `YYYY`=4, `YYYY-MM`=6, `YYYY-MM-DD`=8 for dates; digits after the decimal point for numbers). `lowBoundary()` and `highBoundary()` take an optional output-precision argument.

| Function                    | Description                                                                                                                                                          | Example                                |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
| `precision()`               | Number of significant positions in the input. Trailing zeros on a decimal are preserved.                                                                             | `(1.58700).precision()` → `5`          |
| `lowBoundary([precision])`  | Lowest value in the natural range the input represents. For numbers, `value - 0.5×10^-precision`; for dates/times, fills unspecified components with their minimum.  | `(1.587).lowBoundary()` → `1.5865...`  |
| `highBoundary([precision])` | Highest value in the natural range the input represents. For numbers, `value + 0.5×10^-precision`; for dates/times, fills unspecified components with their maximum. | `(1.587).highBoundary()` → `1.5875...` |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://php-fhir-tools.ardenexal.net/fhirpath/functions/math.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
