diff --git a/.releases/4.33.0.md b/.releases/4.33.0.md new file mode 100644 index 0000000..7672364 --- /dev/null +++ b/.releases/4.33.0.md @@ -0,0 +1,3 @@ +**New Features** + +* Added the `mod` operation for the `Decimal` class. diff --git a/lang/Decimal.js b/lang/Decimal.js index fb297dd..9bdccb4 100644 --- a/lang/Decimal.js +++ b/lang/Decimal.js @@ -101,6 +101,18 @@ module.exports = (() => { return new Decimal(this._big.round(places, modeToUse.value)); } + /** + * Returns a new {@link Decimal} instance with a value that returns + * the remainder of dividing by the value supplied. + * + * @public + * @param {Decimal|Number|String} other + * @returns {Decimal} + */ + mod(other) { + return new Decimal(this._big.mod(getBig(other))); + } + /** * Returns a new {@link Decimal} instance having the absolute value of * the current instance's value. diff --git a/test/specs/lang/DecimalSpec.js b/test/specs/lang/DecimalSpec.js index 00c86c2..98c9f87 100644 --- a/test/specs/lang/DecimalSpec.js +++ b/test/specs/lang/DecimalSpec.js @@ -206,6 +206,14 @@ describe('When instantiating a Decimal', () => { }).toThrow(); }); }); + + describe('and modulo by zero', () => { + it('should throw', () => { + expect(() => { + let e = d.mod(0); + }).toThrow(); + }); + }); }); describe('from the string "1"', () => {