bn.js
bn.js copied to clipboard
Feature request: divRound should be able to round up
I need a way to round up the remained in division. Would that be a good option for divRound?
I don't need this anymore and don't have time to implement it ATM.
I'd like to reopen this. We found a need for divCeil in ethereumjs.
This is the current code we have:
+// Find Ceil(`this` / `num`)
+BN.prototype.divCeil = function divCeil (num) {
+ var dm = this.divmod(num)
+
+ // Fast case - exact division
+ if (dm.mod.isZero()) return dm.div
+
+ // Round up
+ return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1)
+}