Skip to content

Commit

Permalink
chore: remove less-useful signatures for round with units and matrices
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Nov 16, 2023
1 parent cdc45de commit 5dc5524
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 43 deletions.
12 changes: 0 additions & 12 deletions src/function/arithmetic/round.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,6 @@ export const createRound = /* #__PURE__ */ factory(name, dependencies, ({ typed,

'Array | Matrix, Unit': typed.referToSelf(self => (x, unit) => self(x, 0, unit)),

'Unit, Array | Matrix, Unit': typed.referToSelf(self => (x, nCollection, unit) => {
// deep map collection, skip zeros since round(0) = 0
return deepMap(nCollection, (n) => self(x, n, unit), true)
}),

'Unit, number | BigNumber, Array | Matrix': typed.referToSelf(self => (x, n, unitCollection) => {
// deep map collection, skip zeros since round(0) = 0
return deepMap(unitCollection, (unit) => self(x, n, unit), true)
}),

'Unit, Array | Matrix': typed.referToSelf(self => (x, unitCollection) => self(x, 0, unitCollection)),

'Array | Matrix': typed.referToSelf(self => x => {
// deep map collection, skip zeros since round(0) = 0
return deepMap(x, self, true)
Expand Down
7 changes: 0 additions & 7 deletions test/unit-tests/function/arithmetic/round.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ describe('round', function () {
// first argument is a collection
assert.deepStrictEqual(round([unit('2 inch'), unit('3 inch')], unit('cm')), [unit('5 cm'), unit('8 cm')])
assert.deepStrictEqual(round(matrix([unit('2 inch'), unit('3 inch')]), unit('cm')), matrix([unit('5 cm'), unit('8 cm')]))

// decimals is a collection
assert.deepStrictEqual(round(unit('3.12345 cm'), [0, 1, 2], unit('cm')), [unit('3 cm'), unit('3.1 cm'), unit('3.12 cm')])

// unit is a collection
assert.deepStrictEqual(round(unit('3.12345 cm'), [unit('cm'), unit('mm')]), [unit('3 cm'), unit('31 mm')])
assert.deepStrictEqual(round(unit('3.12345 cm'), 1, [unit('cm'), unit('mm')]), [unit('3.1 cm'), unit('31.2 mm')])
})

it('should throw an error if used with a unit without valueless unit', function () {
Expand Down
31 changes: 7 additions & 24 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,13 +1104,10 @@ export interface MathJsInstance extends MathJsFactory {
n?: number | BigNumber
): NoLiteralType<T>
round<U extends MathCollection>(x: MathNumericType, n: U): U
round(x: Unit, n: number | BigNumber, unit: Unit): Unit
round(x: Unit, unit: Unit): Unit
round<U extends MathCollection>(x: U, unit: Unit): U
round(x: Unit, unit: Unit): Unit
round(x: Unit, n: number | BigNumber, unit: Unit): Unit
round<U extends MathCollection>(x: U, n: number | BigNumber, unit: Unit): U
round<U extends MathCollection>(x: Unit, n: U, unit: Unit): U
round<U extends MathCollection>(x: Unit, n: number | BigNumber, unit: U): U
round<U extends MathCollection>(x: Unit, unit: U): U

// End of group of rounding functions

Expand Down Expand Up @@ -4751,34 +4748,20 @@ export interface MathJsChain<TValue> {
this: MathJsChain<MathNumericType | U>,
n: U
): MathJsChain<U>
round(
this: MathJsChain<Unit>,
n: number | BigNumber,
unit: Unit
): MathJsChain<Unit>
round(this: MathJsChain<Unit>, unit: Unit): MathJsChain<Unit>
round<U extends MathCollection>(
this: MathJsChain<U>,
unit: Unit
): MathJsChain<U>
round<U extends MathCollection>(
this: MathJsChain<U>,
n: number | BigNumber,
unit: Unit
): MathJsChain<U>
round<U extends MathCollection>(
round(
this: MathJsChain<Unit>,
n: U,
n: number | BigNumber,
unit: Unit
): MathJsChain<U>
): MathJsChain<Unit>
round<U extends MathCollection>(
this: MathJsChain<Unit>,
this: MathJsChain<U>,
n: number | BigNumber,
unit: U
): MathJsChain<U>
round<U extends MathCollection>(
this: MathJsChain<Unit>,
unit: U
unit: Unit
): MathJsChain<U>

// End of rounding group
Expand Down

0 comments on commit 5dc5524

Please sign in to comment.