diff --git a/docs/datatypes/bignumbers.md b/docs/datatypes/bignumbers.md index 657c96f81..1d53c6ae7 100644 --- a/docs/datatypes/bignumbers.md +++ b/docs/datatypes/bignumbers.md @@ -33,9 +33,7 @@ math.eval('0.1 + 0.2'); // BigNumber, 0.3 The default precision for BigNumber is 64 digits, and can be configured with the option `precision`. -*Important: -BigNumber is not supported by all functions, like `arg`, and `random`. -These functions will downgrade BigNumber to Number, and return a Number.* +Note that BigNumbers are not supported by all functions. ## Round-off errors diff --git a/lib/core/typed.js b/lib/core/typed.js index 00e9a758c..6acd58455 100644 --- a/lib/core/typed.js +++ b/lib/core/typed.js @@ -80,6 +80,13 @@ exports.create = function create(type) { convert: function (x) { return new type.Complex(x.toNumber(), 0); } + }, { + from: 'Fraction', + to: 'BigNumber', + convert: function (x) { + throw new TypeError('Cannot implicitly convert a Fraction to BigNumber or vice versa. ' + + 'Use function bignumber(x) to convert to BigNumber or fraction(x) to convert to Fraction.'); + } }, { from: 'Fraction', to: 'Complex', diff --git a/test/function/arithmetic/multiply.test.js b/test/function/arithmetic/multiply.test.js index f64790b4c..0a002485b 100644 --- a/test/function/arithmetic/multiply.test.js +++ b/test/function/arithmetic/multiply.test.js @@ -59,6 +59,11 @@ describe('multiply', function() { assert.throws(function () {multiply(bignumber(1).div(3), 1/3);}, /Cannot implicitly convert a number with >15 significant digits to BigNumber/); }); + it('should throw an error when multipling mixed fractions and bignumbers', function() { + assert.throws(function () {multiply(math.bignumber('2'), math.fraction(1,3))}, /Cannot implicitly convert a Fraction to BigNumber/); + assert.throws(function () {multiply(math.fraction(1,3), math.bignumber('2'))}, /Cannot implicitly convert a Fraction to BigNumber/); + }); + it('should multiply mixed booleans and bignumbers', function() { assert.deepEqual(multiply(bignumber(0.3), true), bignumber(0.3)); assert.deepEqual(multiply(bignumber(0.3), false), bignumber(0));