> For the complete documentation index, see [llms.txt](https://docs.internetobject.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.internetobject.org/structure-and-syntax/values/number/nan-and-infinity.md).

# NaN and Infinity

The special numeric values represent "Not a Number" and infinite quantities, following IEEE 754. They model the edge cases of numeric computation — an undefined result, or a value beyond the finite range. Only the Number form supports them; BigInt and Decimal do not.

## Syntax

The special values are written as fixed keywords:

```ebnf
specialValue  = nanValue | infinityValue
nanValue      = "NaN"
infinityValue = ["+" | "-"] "Inf"
```

## Structural elements

| Token | Name         | Description                                        |
| ----- | ------------ | -------------------------------------------------- |
| `NaN` | Not a Number | An undefined or unrepresentable numeric result     |
| `Inf` | Infinity     | A value beyond the finite range                    |
| `-`   | Minus sign   | Negative infinity (`-Inf`)                         |
| `+`   | Plus sign    | Explicit positive infinity (`+Inf`); not preserved |

## Valid forms

```ruby
NaN                  # Not a Number
Inf                  # positive infinity
-Inf                 # negative infinity
+Inf                 # positive infinity (explicit sign, not preserved)
```

## Not the special value

The special values are **case-sensitive and spelled exactly**. Any other spelling is not an error — it is simply parsed as an open string (text), so it is *not* the numeric special value:

```ruby
nan                  # open string "nan", not NaN
INF                  # open string "INF", not Inf
infinity             # open string "infinity", not Inf
-NaN                 # open string "-NaN" — NaN cannot be signed
```

> To store one of these as a number, write it exactly: `NaN`, `Inf`, `-Inf`, or `+Inf`. To store the word as text, quote it: `"infinity"`.

## Preservation of structure

Internet Object preserves:

* The exact special value written
* The sign of negative infinity
* Syntactic fidelity as written, except that an explicit `+` sign is not preserved

It does **not** interpret:

* The operations that produced these values
* Comparison or equality semantics (for example, that `NaN` equals nothing, including itself)

Those semantics belong to the application.

## See Also

* [Number](/structure-and-syntax/values/number/number.md) — standard floating-point numbers
* [Numeric Values](/structure-and-syntax/values/number.md) — all numeric forms


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.internetobject.org/structure-and-syntax/values/number/nan-and-infinity.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
