Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 806 Bytes

minimum-and-maximum-values-of-numeric-types.md

File metadata and controls

29 lines (23 loc) · 806 Bytes
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.
MIN
MAX
u8
i8
u128
i128
f32
f64
isize
usize

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" %}