11import assert from 'assert'
22import math from '../../../../src/defaultInstance.js'
33import approx from '../../../../tools/approx.js'
4+ const EPSILON = 1e-13
45const pi = math . pi
56const complex = math . complex
67const matrix = math . matrix
@@ -15,16 +16,16 @@ describe('sin', function () {
1516 } )
1617
1718 it ( 'should return the sine of a number' , function ( ) {
18- approx . equal ( sin ( 0 ) , 0 )
19- approx . equal ( sin ( pi / 8 ) , 0.382683432365090 )
20- approx . equal ( sin ( pi / 4 ) , Math . SQRT1_2 )
21- approx . equal ( sin ( pi / 2 ) , 1 )
22- approx . equal ( sin ( pi * 3 / 4 ) , 0.707106781186548 )
23- approx . equal ( sin ( pi ) , 0 )
24- approx . equal ( sin ( pi * 5 / 4 ) , - 0.707106781186548 )
25- approx . equal ( sin ( pi * 3 / 2 ) , - 1 )
26- approx . equal ( sin ( pi * 7 / 4 ) , - 0.707106781186548 )
27- approx . equal ( sin ( pi * 2 ) , 0 )
19+ approx . equal ( sin ( 0 ) , 0 , EPSILON )
20+ approx . equal ( sin ( pi / 8 ) , 0.382683432365090 , EPSILON )
21+ approx . equal ( sin ( pi / 4 ) , Math . SQRT1_2 , EPSILON )
22+ approx . equal ( sin ( pi / 2 ) , 1 , EPSILON )
23+ approx . equal ( sin ( pi * 3 / 4 ) , 0.707106781186548 , EPSILON )
24+ approx . equal ( sin ( pi ) , 0 , EPSILON )
25+ approx . equal ( sin ( pi * 5 / 4 ) , - 0.707106781186548 , EPSILON )
26+ approx . equal ( sin ( pi * 3 / 2 ) , - 1 , EPSILON )
27+ approx . equal ( sin ( pi * 7 / 4 ) , - 0.707106781186548 , EPSILON )
28+ approx . equal ( sin ( pi * 2 ) , 0 , EPSILON )
2829 } )
2930
3031 it ( 'should return the sine of a bignumber' , function ( ) {
@@ -49,7 +50,7 @@ describe('sin', function () {
4950
5051 // we've had a bug in reducing the period, affecting integer values around multiples of tau (like 6, 7)
5152 for ( let x = - 20 ; x < 20 ; x += 1 ) {
52- approx . equal ( bigmath2 . sin ( bigmath2 . bignumber ( x ) ) . toNumber ( ) , Math . sin ( x ) )
53+ approx . equal ( bigmath2 . sin ( bigmath2 . bignumber ( x ) ) . toNumber ( ) , Math . sin ( x ) , EPSILON )
5354 }
5455
5556 const bigPi = bigmath2 . pi
@@ -73,24 +74,24 @@ describe('sin', function () {
7374 it ( 'should return the sine of a complex number' , function ( ) {
7475 const re = 9.15449914691143
7576 const im = 4.16890695996656
76- approx . deepEqual ( sin ( complex ( '2+3i' ) ) , complex ( re , - im ) )
77- approx . deepEqual ( sin ( complex ( '2-3i' ) ) , complex ( re , im ) )
78- approx . deepEqual ( sin ( complex ( '-2+3i' ) ) , complex ( - re , - im ) )
79- approx . deepEqual ( sin ( complex ( '-2-3i' ) ) , complex ( - re , im ) )
80- approx . deepEqual ( sin ( complex ( 'i' ) ) , complex ( 0 , 1.175201193643801 ) )
81- approx . deepEqual ( sin ( complex ( '1' ) ) , complex ( 0.841470984807897 , 0 ) )
82- approx . deepEqual ( sin ( complex ( '1+i' ) ) , complex ( 1.298457581415977 , 0.634963914784736 ) )
83- approx . deepEqual ( sin ( complex ( '1e-10i' ) ) , complex ( '1e-10i' ) )
77+ approx . deepEqual ( sin ( complex ( '2+3i' ) ) , complex ( re , - im ) , EPSILON )
78+ approx . deepEqual ( sin ( complex ( '2-3i' ) ) , complex ( re , im ) , EPSILON )
79+ approx . deepEqual ( sin ( complex ( '-2+3i' ) ) , complex ( - re , - im ) , EPSILON )
80+ approx . deepEqual ( sin ( complex ( '-2-3i' ) ) , complex ( - re , im ) , EPSILON )
81+ approx . deepEqual ( sin ( complex ( 'i' ) ) , complex ( 0 , 1.175201193643801 ) , EPSILON )
82+ approx . deepEqual ( sin ( complex ( '1' ) ) , complex ( 0.841470984807897 , 0 ) , EPSILON )
83+ approx . deepEqual ( sin ( complex ( '1+i' ) ) , complex ( 1.298457581415977 , 0.634963914784736 ) , EPSILON )
84+ approx . deepEqual ( sin ( complex ( '1e-10i' ) ) , complex ( '1e-10i' ) , EPSILON )
8485 } )
8586
8687 it ( 'should return the sine of an angle' , function ( ) {
87- approx . equal ( sin ( unit ( '45deg' ) ) , 0.707106781186548 )
88- approx . equal ( sin ( unit ( '-45deg' ) ) , - 0.707106781186548 )
88+ approx . equal ( sin ( unit ( '45deg' ) ) , 0.707106781186548 , EPSILON )
89+ approx . equal ( sin ( unit ( '-45deg' ) ) , - 0.707106781186548 , EPSILON )
8990
9091 assert ( math . isBigNumber ( sin ( unit ( math . bignumber ( 45 ) , 'deg' ) ) ) )
91- approx . equal ( sin ( unit ( math . bignumber ( 45 ) , 'deg' ) ) . toNumber ( ) , 0.707106781186548 )
92+ approx . equal ( sin ( unit ( math . bignumber ( 45 ) , 'deg' ) ) . toNumber ( ) , 0.707106781186548 , EPSILON )
9293
93- approx . deepEqual ( sin ( unit ( complex ( '1+i' ) , 'rad' ) ) , complex ( 1.298457581415977 , 0.634963914784736 ) )
94+ approx . deepEqual ( sin ( unit ( complex ( '1+i' ) , 'rad' ) ) , complex ( 1.298457581415977 , 0.634963914784736 ) , EPSILON )
9495 } )
9596
9697 it ( 'should throw an error if called with an invalid unit' , function ( ) {
@@ -104,11 +105,11 @@ describe('sin', function () {
104105 const sin123 = [ 0.84147098480789 , 0.909297426825682 , 0.141120008059867 ]
105106
106107 it ( 'should return the sin of each element of an array' , function ( ) {
107- approx . deepEqual ( sin ( [ 1 , 2 , 3 ] ) , sin123 )
108+ approx . deepEqual ( sin ( [ 1 , 2 , 3 ] ) , sin123 , EPSILON )
108109 } )
109110
110111 it ( 'should return the sin of each element of a matrix' , function ( ) {
111- approx . deepEqual ( sin ( matrix ( [ 1 , 2 , 3 ] ) ) , matrix ( sin123 ) )
112+ approx . deepEqual ( sin ( matrix ( [ 1 , 2 , 3 ] ) ) , matrix ( sin123 ) , EPSILON )
112113 } )
113114
114115 it ( 'should throw an error in case of invalid number of arguments' , function ( ) {
0 commit comments