Cycle calmp

Run Settings
LanguageRust
Language Version
Run Command
use std::cmp::PartialOrd; use std::ops::{Range, Rem, Sub, Add}; fn cycle_calmp<T: Rem<Output=T> + Sub<Output=T> + Add<Output=T> + PartialOrd + Copy>(zero: T, i: T, r: Range<T>) -> T { let lim = (i - r.start) % (r.end - r.start); if lim < zero { return lim + r.end; } else { return lim + r.start; } } fn main() { let r = -2..2; println!("{}", cycle_calmp(0, -4, r.clone())); println!("{}", cycle_calmp(0, -3, r.clone())); println!("{}", cycle_calmp(0, -2, r.clone())); println!("{}", cycle_calmp(0, -1, r.clone())); println!("{}", cycle_calmp(0, 0, r.clone())); println!("{}", cycle_calmp(0, 1, r.clone())); println!("{}", cycle_calmp(0, 2, r.clone())); println!("{}", cycle_calmp(0, 3, r.clone())); println!("{}", cycle_calmp(0, 4, r.clone())); }
Editor Settings
Theme
Key bindings
Full width
Lines