> ## Documentation Index
> Fetch the complete documentation index at: https://docs.effectiveai.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Exact numbers

> Why an RSL rater calculates with exact decimals, reads each input number exactly as sent, and rounds only where the filing says.

[Install Relativities and download the synthetic examples](/relativities/setup) before running this page.

An RSL rater calculates the way an actuary does on paper. `0.1` is exactly one tenth, and
`1.1 + 2.2` is exactly `3.3`. A value changes only at a `round` that the rater writes.

```mermaid theme={null}
flowchart LR
  input["Number in the request"] --> check["Checked against its precision"]
  check --> exact["Exact arithmetic"]
  exact --> round["round, where the filing rounds"]
  round --> output["Premium in exact decimals"]
```

## Why exact numbers matter

A rating manual prints its rates and factors as decimals. Most programs store numbers in binary,
which holds most decimals only approximately. Over a long chain of factors, those small errors
can move a premium by a cent. The result can also depend on the order of the steps.

RSL keeps each value exact through the declared operations. The same implementation and inputs produce the same result across machines.
Calculation order still matters where rounding intervenes. Validate the declared order and rounding rules against the filing and independent examples.

## Inputs arrive exactly

The rater reads each number in a request from its text, so `1000.005` stays `1000.005`. It then
checks the number against its declared precision, and refuses a number off that precision:

```rsl theme={null}
            annual_premium: Num {precision: 0.01} where self in [100, 100000]
```

The sample download includes this rater in `relativities-examples/rsl/exact`:

```python theme={null}
import rslc

rater = rslc.PreparedRater("relativities-examples/rsl/exact")
print(rater.rate('{"Policy": {"annual_premium": 1000.005}}'))
# {"ok":false,"refusal":{"error":"InvalidInputs","truncated":false,"violations":[{"cite":null,"code":"INPUT-PRECISION","constraint":"annual_premium: Num {precision: 0.01} where self in [100, 100000]","message":"annual_premium must be a multiple of 0.01","path":"Policy.annual_premium","value":1000.005}]}}
print(rater.rate('{"Policy": {"annual_premium": "1000"}}'))
# {"ok":false,"refusal":{"error":"InvalidInputs","truncated":false,"violations":[{"cite":null,"code":"INPUT-TYPE","constraint":"annual_premium: Num {precision: 0.01} where self in [100, 100000]","message":"annual_premium must be a number","path":"Policy.annual_premium","value":"1000"}]}}
print(rater.rate('{"Policy": {"annual_premium": 1e3}}'))
# {"ok":true,"outputs":{"Policy":{"installment":83.33}}}
```

* Send numbers as JSON numbers. A number inside a string is a type error.
* An exponent such as `1e3` is fine, because it names an exact value.
* The rater uses each input as sent. Round an input before you send it.

## Division keeps the exact value

`1000 / 12` is exactly `250/3`, and the calculation keeps that value until a `round`:

```rsl theme={null}
        step installments {
            monthly: Num = self.annual_premium / 12,
            installment: Premium [cite: manual:p11] = round(self.monthly, 2, half_up)
        }
```

```python theme={null}
print(rater.rate('{"Policy": {"annual_premium": 1000}}', detailed=True))
# {"ok":true,"outputs":{"Policy":{"monthly":{"$rational":"250/3"},"installment":83.33}}}
```

A value with a short decimal form comes back as a JSON number. Any other value, such as
`250/3`, comes back as `{"$rational": "p/q"}`. A premium always rounds, so it always comes back
as a decimal.

## A precision on a calculation is a promise

A calculation typed with a precision, such as `Money` in whole cents, promises values on that
precision. The check proves the promise, and the rater rounds only where a `round` says so.
[What rslc checks and guarantees](/relativities/rsl/explanation/checks-and-guarantees) shows the message for a
broken promise.

## Related

* [Round a premium](/relativities/rsl/how-to/round-a-premium) shows each rounding mode.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.