From e2fa36093c58a8d8d97b37a182d45e7d804ab075 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Tue, 19 Mar 2019 18:12:11 +0200 Subject: Generic div_round_up() --- src/lib.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bccc797..0ecc05f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -use std::ops::{Add, Sub, Mul}; +use std::ops::{Add, Sub, Div}; pub struct BCH { m: i16, @@ -8,10 +8,14 @@ pub struct BCH { n:i16, } -fn div_round_up(a: i16, b: i16) -> i16 { - (a + b - 1) / b +pub fn div_round_up(a: T, b: T) -> T +where + T: Copy + Add + Sub + Div + From, +{ + (a + b - T::from(1)) / b } + impl BCH { pub fn build_gf_tables(self) { -- cgit v1.3.1