Skip to content

Commit

Permalink
Release v5.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Oct 5, 2018
1 parent aadb63e commit a715786
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
7 changes: 5 additions & 2 deletions HISTORY.md
@@ -1,10 +1,13 @@
# History

# not yet released, version 5.2.0
# 2018-10-05, version 5.2.0

- Implemented support for chained conditionals like `10 < x <= 50`.
Thanks @ericman314.
- Fix #1240, allow units having just a value and no unit. Thanks @ericman314.
- Add an example showing a proof of concept of using `BigInt` in mathjs.
- Fixed #1269: Bugfix for BigNumber divided by unit. Thanks @ericman314.
- Fixed #1240: allow units having just a value and no unit.
Thanks @ericman314.


## 2018-09-09, version 5.1.2
Expand Down
56 changes: 56 additions & 0 deletions examples/advanced/use_bigint.js
@@ -0,0 +1,56 @@
// This example demonstrates how you could integrate support for BigInt
// in mathjs. It's just a proof of concept, for full support you will
// have to defined more functions and define conversions from and to
// other data types.

const math = require('../../index')

math.import({
name: 'BigInt',
path: 'type', // will be imported into math.type.BigInt
factory: (type, config, load, typed) => {
typed.addType({
name: 'BigInt',
test: (x) => typeof x === 'bigint' // eslint-disable-line
})

// we can also add conversions here from number or string to BigInt
// and vice versa using typed.addConversion(...)

return BigInt // eslint-disable-line
},

// disable lazy loading as this factory has side
// effects: it adds a type and a conversion.
lazy: false
})

math.import({
name: 'bigint',
factory: (type, config, load, typed) => {
return typed('bigint', {
'number | string ': (x) => BigInt(x) // eslint-disable-line
})
}
})

math.import({
name: 'add',
factory: (type, config, load, typed) => {
return typed('add', {
'BigInt, BigInt': (a, b) => a + b
})
}
})

math.import({
name: 'pow',
factory: (type, config, load, typed) => {
return typed('pow', {
'BigInt, BigInt': (a, b) => a ** b
})
}
})

console.log(math.eval('bigint(4349) + bigint(5249)'))
console.log(math.eval('bigint(4349) ^ bigint(5249)'))
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "mathjs",
"version": "5.1.2",
"version": "5.2.0",
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with different data types like numbers, big numbers, complex numbers, fractions, units, and matrices.",
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
"contributors": [
Expand Down
5 changes: 4 additions & 1 deletion src/type/numeric.js
Expand Up @@ -50,5 +50,8 @@ function factory (type, config, load, typed) {
return numeric
}

exports.name = 'numeric'
// FIXME: expose numeric in the math namespace after we've decided on a name and have written proper docs for this function. See https://github.com/josdejong/mathjs/pull/1270
// exports.name = 'type._numeric'
exports.path = 'type'
exports.name = '_numeric'
exports.factory = factory
2 changes: 1 addition & 1 deletion src/version.js
@@ -1,3 +1,3 @@
module.exports = '5.1.2'
module.exports = '5.2.0'
// Note: This file is automatically generated when building math.js.
// Changes made in this file will be overwritten.
3 changes: 2 additions & 1 deletion test/type/numeric.test.js
@@ -1,6 +1,6 @@
const assert = require('assert')
const math = require('../../src/main')
const numeric = math.numeric
const numeric = math.type._numeric

describe('numeric', function () {
it('should throw if called with wrong number of arguments', function () {
Expand Down Expand Up @@ -80,6 +80,7 @@ describe('numeric', function () {
})

it('should LaTeX numeric', function () {
math.numeric = math.type._numeric // FIXME: this is a workaround until we have exposed numeric in the math namespace
const expr1 = math.parse('numeric(3.14, "number")')
const expr2 = math.parse('numeric("3.141592653589793238462643383279501", "BigNumber")')
const expr3 = math.parse('numeric(22/7, "Fraction")')
Expand Down

0 comments on commit a715786

Please sign in to comment.