title | timestamp | author | published | description | tags | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Minimum and maximum values of Rust numeric types |
2023-10-03 00:00:01 -0700 |
szabgab |
true |
To avoid overflowing or underflowing the numeric types one can check against the minimum and maximum possible values. |
|
If you'd like to make sure that your computations don't result in a number that cannot fit into the numeric type you are using, you can always makes some comparison before the computation to the minimum and maximum values of the numeric types.
Here you can see the MIN and MAX values of most of the numeric types of Rust:
{% include file="examples/min-max-values/src/main.rs" %}
{% include file="examples/min-max-values/out.txt" %}