# number_expression

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-controls/utils/number_expression/

**module** · [`ferroui-controls`](/docs/0.5.0/api/ferroui-controls/) · v0.5.0

```rust
module number_expression
```

The arithmetic expressions of WinUI's NumberBox (`NumberBoxParser`,
`controls/dev/NumberBox/NumberBoxParser.cpp` of microsoft-ui-xaml, commit
`7e4b0c2096be402f51cc8f7d203ebf67cff183d0`; MIT, Copyright (c) Microsoft Corporation, see
NOTICE.md), shared by the number editors of the crate: `NumberBox`
evaluates them with `f64`, and the evaluator is generic over the number type so that an
editor of `Decimal` values evaluates them exactly.

The grammar is WinUI's: numbers, the binary operators `+`, `-`, `*`, `/` and `^`, and
parentheses. `^` binds tighter than `*` and `/`, which bind tighter than `+` and `-`, and every
operator, `^` included, associates from left to right (`2 ^ 3 ^ 2` is 64). A number is the
longest run of characters that are not operators, parentheses or white space, optionally after
a minus sign, and the caller's parser reads it (the number formatter of the editor); a minus
sign before a parenthesis is not part of the grammar. Spaces separate tokens; other white space
is an error.

Deviation (docs/porting/winui-controls.md, Input): WinUI's parser has no bounds and returns
`null` for every error; this one rejects an input longer than 64 KiB or with more than 4096
tokens, never recurses, and reports what is wrong and where.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/utils/number_expression.rs#L1)

## Contents

- [`ExpressionNumber`](/docs/0.5.0/api/ferroui-controls/utils/number_expression/trait-expressionnumber/) — trait
- [`NumberExpressionErrorKind`](/docs/0.5.0/api/ferroui-controls/utils/number_expression/enum-numberexpressionerrorkind/) — enum
- [`NumberExpressionError`](/docs/0.5.0/api/ferroui-controls/utils/number_expression/struct-numberexpressionerror/) — struct
- [`evaluate_number_expression`](/docs/0.5.0/api/ferroui-controls/utils/number_expression/function-evaluate_number_expression/) — function

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
