Skip to content

Commit aedbee5

Browse files
author
kyle-compute
authored
fix: #3512 sign of zero not returning zero in case of a fraction
* sign of zero fraction should return 0/1 instead of 1/1 * moved fraction zero test into correct fraction block * moved fraction zero test into correct fraction block
1 parent 26c70ea commit aedbee5

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/function/arithmetic/sign.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const createSign = /* #__PURE__ */ factory(name, dependencies, ({ typed,
5252
},
5353

5454
Fraction: function (x) {
55-
return new Fraction(x.s)
55+
return x.n === 0n ? new Fraction(0) : new Fraction(x.s)
5656
},
5757

5858
// deep map collection, skip zeros since sign(0) = 0

test/unit-tests/function/arithmetic/sign.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe('sign', function () {
3737
assert.strictEqual(math.sign(a).toString(), '1')
3838
assert.strictEqual(math.sign(fraction(-0.5)).toString(), '-1')
3939
assert.strictEqual(a.toString(), '0.5')
40+
assert.deepStrictEqual(math.sign(math.fraction(0)), math.fraction(0))
4041
})
4142

4243
it('should calculate the sign of a complex value', function () {

0 commit comments

Comments
 (0)