Skip to content

Corner cases of "modint" when mod = 1 #110

Closed
@rsk0315

Description

@rsk0315

let mut r = Self::raw(1);

impl<M: Modulus> Product<_> for StaticModInt<M> { fn product(_) -> _ { _(Self::raw(1), Mul::mul) } }

impl<I: Id > Product<_> for DynamicModInt<I> { fn product(_) -> _ { _(Self::raw(1), Mul::mul) } }

The identity of multiplication should be Self::new(1)(not raw but new), because of following (corner) cases:

use ac_library_rs::ModInt;

ModInt::set_modulus(1); // !!

let x: ModInt = std::iter::empty::<ModInt>().product();
assert_eq!(x.val(), 0);

let y = ModInt::new(123).pow(0);
assert_eq!(y.val(), 0);

Note that the original ACL allows to use modint::set_mod(1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions