bn.js icon indicating copy to clipboard operation
bn.js copied to clipboard

Feature request: divRound should be able to round up

Open wanderer opened this issue 9 years ago • 2 comments

I need a way to round up the remained in division. Would that be a good option for divRound?

wanderer avatar Dec 09 '15 05:12 wanderer

I don't need this anymore and don't have time to implement it ATM.

wanderer avatar Dec 11 '15 16:12 wanderer

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)
 +}

axic avatar Nov 29 '17 22:11 axic