blob: fcb76e69c2a8d61a8bf48f1d4f0d813b3be6eef2 [file] [log] [blame] [view]
## fi-0066: Constant overflows type {:#fi-0066}
A constant value cannot fall outside of the range inherent to its underlying
type:
{% include "docs/reference/fidl/language/error-catalog/label/_bad.md" %}
```fidl
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/bad/fi-0066.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
```
The problem may be fixed either by changing the value to fit within the type's
range:
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
```fidl
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0066-a.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
```
Or otherwise by changing to the type to accommodate the currently overflowing
value:
{% include "docs/reference/fidl/language/error-catalog/label/_good.md" %}
```fidl
{% includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="tools/fidl/fidlc/tests/fidl/good/fi-0066-b.test.fidl" exclude_regexp="\/\/ (Copyright 20|Use of|found in).*" %}
```
This error exclusively concerns FIDL's numeric types, all of which have the
capacity to overflow. The ranges are sourced from the C++ `std::numeric_limits`
[interface][cpp-ref-numeric-limits] and are as follows:
Type | Minimum | Maximum |
| --- | --- | --- |
| `int8` | -128 | 127 |
| `int16` | 32768 | 32767 |
| `int32` | 2147483648 | 2147483647 |
| `int64` | 9223372036854775808 | 9223372036854775807 |
| `uint8` | 0 | 255 |
| `uint16` | 0 | 65536 |
| `uint32` | 0 | 4294967295 |
| `uint64` | 0 | 18446744073709551615 |
| `float32` | -3.40282e+38 | 3.40282e+38 |
| `float64` | -1.79769e+308 | 1.79769e+308 |
[cpp-ref-numeric-limits]: https://en.cppreference.com/w/cpp/types/climits