25
25
var tape = require ( 'tape' ) ;
26
26
var EPS_F64 = require ( '@stdlib/constants/float64/eps' ) ;
27
27
var EPS_F32 = require ( '@stdlib/constants/float32/eps' ) ;
28
- var f32 = require ( '@stdlib/number/float64/base/to-float32' ) ;
29
28
var Number = require ( '@stdlib/number/ctor' ) ;
30
29
var Boolean = require ( '@stdlib/boolean/ctor' ) ;
31
30
var Complex128 = require ( '@stdlib/complex/float64/ctor' ) ;
@@ -66,7 +65,6 @@ tape( 'the function returns `true` if provided two arguments which are the same
66
65
new Complex64 ( 5.0 , 2.0 )
67
66
] ;
68
67
for ( i = 0 ; i < values . length ; i ++ ) {
69
- console . log ( values [ i ] ) ;
70
68
t . strictEqual ( isAlmostEqual ( values [ i ] , values [ i ] , 0 ) , true , 'returns expected value' ) ;
71
69
t . strictEqual ( isAlmostEqual ( values [ i ] , values [ i ] , 1 ) , true , 'returns expected value' ) ;
72
70
}
@@ -87,7 +85,6 @@ tape( 'the function returns `true` if provided two arguments which are the same
87
85
} ) ;
88
86
89
87
tape ( 'the function returns `true` if provided two arguments which are approximately equal within a specified number of ULPs' , function test ( t ) {
90
- t . strictEqual ( isAlmostEqual ( f32 ( 1.0 ) , f32 ( f32 ( 1.0 ) + EPS_F32 ) , 1 ) , true , 'returns expected value' ) ;
91
88
t . strictEqual ( isAlmostEqual ( 1.0 , 1.0 + EPS_F64 , 1 ) , true , 'returns expected value' ) ;
92
89
t . strictEqual ( isAlmostEqual ( 1.0 + EPS_F64 , 1.0 , 1 ) , true , 'returns expected value' ) ;
93
90
t . strictEqual ( isAlmostEqual ( 1.0 , 1.0 + EPS_F64 + EPS_F64 , 2 ) , true , 'returns expected value' ) ;
@@ -110,6 +107,7 @@ tape( 'the function returns `false` if provided two arguments which are not appr
110
107
5 ,
111
108
3.14 ,
112
109
- 3.14 ,
110
+ new Number ( 5 ) ,
113
111
true ,
114
112
false ,
115
113
new Boolean ( true ) ,
@@ -130,6 +128,7 @@ tape( 'the function returns `false` if provided two arguments which are not appr
130
128
- 5 ,
131
129
- 3.14 ,
132
130
3.14 ,
131
+ new Number ( 5 ) ,
133
132
false ,
134
133
true ,
135
134
new Boolean ( true ) ,
@@ -144,8 +143,6 @@ tape( 'the function returns `false` if provided two arguments which are not appr
144
143
new Complex64 ( 5.0 , - 2.0 )
145
144
] ;
146
145
for ( i = 0 ; i < a . length ; i ++ ) {
147
- console . log ( a [ i ] , b [ i ] ) ;
148
- console . log ( isAlmostEqual ( a [ i ] , b [ i ] , 1 ) ) ;
149
146
t . strictEqual ( isAlmostEqual ( a [ i ] , b [ i ] , 1 ) , false , 'returns expected value' ) ;
150
147
}
151
148
@@ -157,3 +154,41 @@ tape( 'the function returns `false` if provided two arguments which are not appr
157
154
158
155
t . end ( ) ;
159
156
} ) ;
157
+
158
+ tape ( 'the function returns `false` if either input value is `NaN` or in the case of complex numbers, if either the real or imaginary component is `NaN`' , function test ( t ) {
159
+ var a ;
160
+ var b ;
161
+ var i ;
162
+
163
+ a = [
164
+ NaN ,
165
+ NaN ,
166
+ new Complex128 ( NaN , 3.0 ) ,
167
+ new Complex64 ( 5.0 , NaN ) ,
168
+ new Complex128 ( NaN , NaN ) ,
169
+ new Complex64 ( NaN , NaN )
170
+ ] ;
171
+ b = [
172
+ NaN ,
173
+ 1.0 ,
174
+ new Complex128 ( 1.0 , 2.0 ) ,
175
+ new Complex64 ( 3.0 , 4.0 ) ,
176
+ new Complex128 ( NaN , NaN ) ,
177
+ new Complex64 ( NaN , NaN )
178
+ ] ;
179
+ for ( i = 0 ; i < a . length ; i ++ ) {
180
+ t . strictEqual ( isAlmostEqual ( a [ i ] , b [ i ] , 1 ) , false , 'returns expected value' ) ;
181
+ }
182
+
183
+ t . end ( ) ;
184
+ } ) ;
185
+
186
+ tape ( 'the function does not distinguish between `-0` and `+0`' , function test ( t ) {
187
+ t . strictEqual ( isAlmostEqual ( - 0.0 , 0.0 , 0 ) , true , 'returns expected value' ) ;
188
+ t . strictEqual ( isAlmostEqual ( 0.0 , - 0.0 , 0 ) , true , 'returns expected value' ) ;
189
+
190
+ t . strictEqual ( isAlmostEqual ( new Complex128 ( - 0.0 , 3.0 ) , new Complex128 ( 0.0 , 3.0 ) , 1 ) , true , 'returns expected value' ) ;
191
+ t . strictEqual ( isAlmostEqual ( new Complex64 ( - 0.0 , 3.0 ) , new Complex64 ( 0.0 , 3.0 ) , 1 ) , true , 'returns expected value' ) ;
192
+
193
+ t . end ( ) ;
194
+ } ) ;
0 commit comments