mathjs 3.1.3 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mathjs might be problematic. Click here for more details.

@@ -1,35 +1,46 @@
1
- var assert = require('assert'),
2
- error = require('../../../lib/error/index'),
3
- math = require('../../../index'),
4
- approx = require('../../../tools/approx'),
5
- pi = math.pi,
6
- complex = math.complex,
7
- matrix = math.matrix,
8
- unit = math.unit,
9
- sinh = math.sinh,
10
- bigmath = math.create({number: 'BigNumber', precision: 20});
1
+ var assert = require('assert');
2
+ var error = require('../../../lib/error/index');
3
+ var math = require('../../../index');
4
+ var approx = require('../../../tools/approx');
5
+ var complex = math.complex;
6
+ var matrix = math.matrix;
7
+ var unit = math.unit;
8
+ var sinh = math.sinh;
9
+ var bigmath = math.create({number: 'BigNumber', precision: 20});
10
+
11
+ var EPSILON = 1e-14;
12
+
11
13
 
12
14
  describe('sinh', function() {
13
15
  it('should return the sinh of a boolean', function () {
14
- approx.equal(sinh(true), 1.1752011936438014);
15
- approx.equal(sinh(false), 0);
16
+ assert.equal(sinh(true), 1.1752011936438014);
17
+ assert.equal(sinh(false), 0);
16
18
  });
17
19
 
18
20
  it('should return the sinh of a null', function () {
19
- approx.equal(sinh(null), 0);
21
+ assert.equal(sinh(null), 0);
20
22
  });
21
23
 
22
24
  it('should return the sinh of a number', function() {
23
- approx.equal(sinh(0), 0);
24
- approx.equal(sinh(pi), 11.548739357257748);
25
- approx.equal(sinh(1), 1.1752011936438014);
25
+ approx.equal(sinh(-2), -3.62686040784701876766821398280126170488634201232113572130, EPSILON);
26
+ approx.equal(sinh(-0.5), -0.52109530549374736162242562641149155910592898261148052794, EPSILON);
27
+ approx.equal(sinh(0), 0, EPSILON);
28
+ approx.equal(sinh(0.3), 0.304520293447142618958435267005095229098024232680179727377, EPSILON);
29
+ approx.equal(sinh(0.5), 0.521095305493747361622425626411491559105928982611480527946, EPSILON);
30
+ approx.equal(sinh(0.8), 0.888105982187623006574717573189756980559709596888150052610, EPSILON);
31
+ approx.equal(sinh(1), 1.175201193643801456882381850595600815155717981334095870229, EPSILON);
32
+ approx.equal(sinh(2), 3.626860407847018767668213982801261704886342012321135721309, EPSILON);
26
33
  });
27
34
 
28
- it('should return the sinh of very small numbers (avoid returning zero)', function() {
29
- // If sinh returns 0, that is bad, so we are using assert.equal, not approx.equal
30
- assert.equal(sinh(-1e-10), -1e-10);
31
- assert.equal(sinh(1e-50), 1e-50);
32
- })
35
+ if (!/v0\.10|v0\.12/.test(process.version)) {
36
+ // skip this test on node v0.10 and v0.12, which have a numerical issue
37
+
38
+ it('should return the sinh of very small numbers (avoid returning zero)', function() {
39
+ // If sinh returns 0, that is bad, so we are using assert.equal, not approx.equal
40
+ assert.equal(sinh(-1e-10), -1e-10);
41
+ assert.equal(sinh(1e-50), 1e-50);
42
+ });
43
+ }
33
44
 
34
45
  it('should return the sinh of a bignumber', function() {
35
46
  var sinhBig = bigmath.sinh;
@@ -56,19 +67,19 @@ describe('sinh', function() {
56
67
  });
57
68
 
58
69
  it('should return the sinh of a complex number', function() {
59
- approx.deepEqual(sinh(complex('1')), complex(1.1752011936438014, 0));
60
- approx.deepEqual(sinh(complex('i')), complex(0, 0.8414709848079));
61
- approx.deepEqual(sinh(complex('2 + i')), complex(1.9596010414216, 3.1657785132162));
70
+ approx.deepEqual(sinh(complex('1')), complex(1.1752011936438014, 0), EPSILON);
71
+ approx.deepEqual(sinh(complex('i')), complex(0, 0.8414709848079), EPSILON);
72
+ approx.deepEqual(sinh(complex('2 + i')), complex(1.9596010414216, 3.1657785132162), EPSILON);
62
73
  });
63
74
 
64
75
  it('should return the sinh of an angle', function() {
65
- approx.equal(sinh(unit('90deg')), 2.3012989023073);
66
- approx.equal(sinh(unit('-45deg')), -0.86867096148601);
76
+ approx.equal(sinh(unit('90deg')), 2.3012989023073, EPSILON);
77
+ approx.equal(sinh(unit('-45deg')), -0.86867096148601, EPSILON);
67
78
 
68
79
  assert(sinh(unit(math.bignumber(90), 'deg')).isBigNumber);
69
- approx.equal(sinh(unit(math.bignumber(90), 'deg')).toNumber(), 2.3012989023073);
80
+ approx.equal(sinh(unit(math.bignumber(90), 'deg')).toNumber(), 2.3012989023073, EPSILON);
70
81
 
71
- approx.deepEqual(sinh(unit(complex('2 + i'), 'rad')), complex(1.9596010414216, 3.1657785132162));
82
+ approx.deepEqual(sinh(unit(complex('2 + i'), 'rad')), complex(1.9596010414216, 3.1657785132162), EPSILON);
72
83
  });
73
84
 
74
85
  it('should throw an error if called with an invalid unit', function() {
@@ -82,11 +93,11 @@ describe('sinh', function() {
82
93
  var sinh123 = [1.1752011936438014, 3.626860407847, 10.01787492741];
83
94
 
84
95
  it('should return the sinh of each element of an array', function() {
85
- approx.deepEqual(sinh([1,2,3]), sinh123);
96
+ approx.deepEqual(sinh([1,2,3]), sinh123, EPSILON);
86
97
  });
87
98
 
88
99
  it('should return the sinh of each element of a matrix', function() {
89
- approx.deepEqual(sinh(matrix([1,2,3])), matrix(sinh123));
100
+ approx.deepEqual(sinh(matrix([1,2,3])), matrix(sinh123), EPSILON);
90
101
  });
91
102
 
92
103
  it('should throw an error in case of invalid number of arguments', function() {