Skip to content

Commit

Permalink
Added mod operation to the Decimal class
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor-Losev committed Sep 7, 2023
1 parent 0895826 commit 364b70b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .releases/4.33.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**New Features**

* Added the `mod` operation for the `Decimal` class.
12 changes: 12 additions & 0 deletions lang/Decimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions test/specs/lang/DecimalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"', () => {
Expand Down

0 comments on commit 364b70b

Please sign in to comment.