你会如何进行天花板划分?

问题描述 投票:0回答:3

避免转换为浮点数是必要的。

rust integer-division
3个回答
16
投票

rust stable v1.61.0 分支:

ceil(a/b)
(a + b - 1) / b
如果你知道该添加不会溢出。

每晚:https://doc.rust-lang.org/std/primitive.i32.html#method.div_ceil


2
投票

您可以使用

divrem
板条箱,具体
div_ceil


0
投票

来自 Rust 标准库 div_ceil:

// pub const fn div_ceil(self, rhs: Self) -> Self;
//     Calculates the quotient of self and rhs, 
//     rounding the result towards positive infinity.

let number: u32 = 122023;
let result = number.div_ceil(10000); // 13
© www.soinside.com 2019 - 2024. All rights reserved.