Skip to content

Commit 6c292cd

Browse files
committed
02_basic_calculator/09_saturating
1 parent 9da3853 commit 6c292cd

File tree

1 file changed

+2
-2
lines changed
  • exercises/02_basic_calculator/09_saturating/src

1 file changed

+2
-2
lines changed

exercises/02_basic_calculator/09_saturating/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
pub fn factorial(n: u32) -> u32 {
2-
let mut result = 1;
2+
let mut result: u32 = 1;
33
for i in 1..=n {
44
// Use saturating multiplication to stop at the maximum value of u32
55
// rather than overflowing and wrapping around
6-
result *= i;
6+
result = result.saturating_mul(i);
77
}
88
result
99
}

0 commit comments

Comments
 (0)