Skip to content

Commit 4c71405

Browse files
authored
Updated inv-mod to be consistent with existing u256-inv-mod impl. (#8584)
1 parent da96616 commit 4c71405

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

corelib/src/math.cairo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn inv_mod<
8989
a: NonZero<T>, n: NonZero<T>,
9090
) -> Option<T> {
9191
if core::num::traits::One::<T>::is_one(@n.into()) {
92-
return Some(core::num::traits::Zero::zero());
92+
return None;
9393
}
9494
let (g, s, _, sub_direction) = egcd(a, n);
9595
if g.is_one() {

corelib/src/test/math_test.cairo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ fn test_inv_mod() {
4646
assert(math::inv_mod(1, 24) == Some(1_u16), 'inv_mod(1, 24) != 1');
4747
assert(math::inv_mod(1, 5) == Some(1_u32), 'inv_mod(1, 5) != 1');
4848
assert(math::inv_mod(8, 24) == Option::<usize>::None, 'inv_mod(8, 24) != None');
49-
assert(math::inv_mod(1, 1) == Some(0_usize), 'inv_mod(1, 1) != 0');
50-
assert(math::inv_mod(7, 1) == Some(0_usize), 'inv_mod(7, 1) != 0');
49+
assert_eq!(math::inv_mod(1, 1), Option::<usize>::None);
50+
assert_eq!(math::inv_mod(7, 1), Option::<usize>::None);
5151
}
5252

5353
#[test]

0 commit comments

Comments
 (0)