193: unwrap: comments, names r=jordens a=jordens



Co-authored-by: Robert Jördens <rj@quartiq.de>
This commit is contained in:
bors[bot] 2020-12-07 12:47:31 +00:00 committed by GitHub
commit 80e92b6949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -18,14 +18,14 @@ pub fn overflowing_sub(y: i32, x: i32) -> (i32, i8) {
/// Overflow unwrapper.
///
/// This is unwrapping as in the phase unwrapping context, not unwrapping as
/// in the `Result`/`Option` context.
/// This is unwrapping as in the phase and overflow unwrapping context, not
/// unwrapping as in the `Result`/`Option` context.
#[derive(Copy, Clone, Default, Deserialize, Serialize)]
pub struct Unwrapper {
// last input
x: i32,
// last wraps
v: i32,
w: i32,
}
impl Unwrapper {
@ -35,13 +35,13 @@ impl Unwrapper {
/// * `x`: New sample
///
/// Returns:
/// A tuple containing the (wrapped) difference `x - x_old` and the signed
/// number of wraps accumulated by `x`.
/// A tuple containing the (wrapped) difference `x - x_old` and the
/// signed number of wraps accumulated by the new sample.
pub fn update(&mut self, x: i32) -> (i32, i32) {
let (dx, v) = overflowing_sub(x, self.x);
let (dx, dw) = overflowing_sub(x, self.x);
self.x = x;
self.v = self.v.saturating_add(v as i32);
(dx, self.v)
self.w = self.w.wrapping_add(dw as i32);
(dx, self.w)
}
}