Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Comment Inconsistency #428

Closed
YichiZhang0613 opened this issue Feb 9, 2025 · 0 comments · Fixed by #429 or #430
Closed

Code Comment Inconsistency #428

YichiZhang0613 opened this issue Feb 9, 2025 · 0 comments · Fixed by #429 or #430

Comments

@YichiZhang0613
Copy link
Contributor

In uint-main/src/bits.rs, the code will panic if index == byte width(in the example is 8), while the comment indicates that code will panic if index > byte width, so I think maybe >= should replace "exceeds".

/// # Panics
    ///
    /// Panics if `index` exceeds the byte width of the number.
/// ```should_panic
/// # use ruint::uint;
/// let x = uint!(0x1234567890_U64);
/// let _ = x.byte(8);
pub const fn byte(&self, index: usize) -> u8 {
    #[cfg(target_endian = "little")]
    {
        self.as_le_slice()[index]
    }

    #[cfg(target_endian = "big")]
    #[allow(clippy::cast_possible_truncation)] // intentional
    {
        (self.limbs[index / 8] >> ((index % 8) * 8)) as u8
    }
}

In uint-main/src/algorithms/div/knuth.rs, the comment indicates that panic if divisor.len()< 2 and numerator.len() < 2, while the code panics if divisor.len()< 3 and numerator.len() < 3

/// Requires
/// * the highest limb of the divisor to be non-zero,
/// * the `divisor` and `numerator` to be at least two limbs, and
/// * `numerator` is at least as long as `divisor`.
///
/// # Panics
///
/// May panic if the above requirements are not met.
#[inline]
#[allow(clippy::many_single_char_names)]
pub fn div_nxm(numerator: &mut [u64], divisor: &mut [u64]) {
    debug_assert!(divisor.len() >= 3);
    debug_assert!(numerator.len() >= divisor.len());
    debug_assert!(*divisor.last().unwrap() >= 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant