21
21
// MODULES //
22
22
23
23
var tape = require ( 'tape' ) ;
24
- var isnan = require ( '@stdlib/math/base/assert/is-nan' ) ;
25
- var absf = require ( '@stdlib/math/base/special/absf' ) ;
24
+ var isnanf = require ( '@stdlib/math/base/assert/is-nanf' ) ;
25
+ var f32 = require ( '@stdlib/number/float64/base/to-float32' ) ;
26
+ var ulpdiff = require ( '@stdlib/number/float32/base/ulp-difference' ) ;
27
+ var isPositiveZerof = require ( '@stdlib/math/base/assert/is-positive-zerof' ) ;
26
28
var PINF = require ( '@stdlib/constants/float32/pinf' ) ;
27
29
var NINF = require ( '@stdlib/constants/float32/ninf' ) ;
28
- var EPS = require ( '@stdlib/constants/float32/eps' ) ;
29
30
var expf = require ( './../lib' ) ;
30
31
31
32
32
33
// FIXTURES //
33
34
34
- var mediumNegative = require ( './fixtures/julia/medium_negative_float32 .json' ) ;
35
- var mediumPositive = require ( './fixtures/julia/medium_positive_float32 .json' ) ;
36
- var smallNegative = require ( './fixtures/julia/small_negative_float32 .json' ) ;
37
- var smallPositive = require ( './fixtures/julia/small_positive_float32 .json' ) ;
38
- var tiny = require ( './fixtures/julia/tiny_float32 .json' ) ;
35
+ var mediumNegative = require ( './fixtures/julia/medium_negative .json' ) ;
36
+ var mediumPositive = require ( './fixtures/julia/medium_positive .json' ) ;
37
+ var smallNegative = require ( './fixtures/julia/small_negative .json' ) ;
38
+ var smallPositive = require ( './fixtures/julia/small_positive .json' ) ;
39
+ var tiny = require ( './fixtures/julia/tiny .json' ) ;
39
40
40
41
41
42
// TESTS //
@@ -48,8 +49,6 @@ tape( 'main export is a function', function test( t ) {
48
49
49
50
tape ( 'the function accurately computes the natural exponential function for negative medium numbers' , function test ( t ) {
50
51
var expected ;
51
- var delta ;
52
- var tol ;
53
52
var x ;
54
53
var v ;
55
54
var i ;
@@ -58,18 +57,16 @@ tape( 'the function accurately computes the natural exponential function for neg
58
57
expected = mediumNegative . expected ;
59
58
60
59
for ( i = 0 ; i < x . length ; i ++ ) {
60
+ x [ i ] = f32 ( x [ i ] ) ;
61
+ expected [ i ] = f32 ( expected [ i ] ) ;
61
62
v = expf ( x [ i ] ) ;
62
- delta = absf ( v - expected [ i ] ) ;
63
- tol = 50 * EPS * absf ( expected [ i ] ) ;
64
- t . ok ( delta <= tol , 'within tolerance. x: ' + x [ i ] + '. Value: ' + v + '. Expected: ' + expected [ i ] + '. Tolerance: ' + tol + '.' ) ;
63
+ t . strictEqual ( ulpdiff ( v , expected [ i ] ) <= 1 , true , 'returns expected value' ) ;
65
64
}
66
65
t . end ( ) ;
67
66
} ) ;
68
67
69
68
tape ( 'the function accurately computes the natural exponential function for positive medium numbers' , function test ( t ) {
70
69
var expected ;
71
- var delta ;
72
- var tol ;
73
70
var x ;
74
71
var v ;
75
72
var i ;
@@ -78,18 +75,16 @@ tape( 'the function accurately computes the natural exponential function for pos
78
75
expected = mediumPositive . expected ;
79
76
80
77
for ( i = 0 ; i < x . length ; i ++ ) {
78
+ x [ i ] = f32 ( x [ i ] ) ;
79
+ expected [ i ] = f32 ( expected [ i ] ) ;
81
80
v = expf ( x [ i ] ) ;
82
- delta = absf ( v - expected [ i ] ) ;
83
- tol = 50 * EPS * absf ( expected [ i ] ) ;
84
- t . ok ( delta <= tol , 'within tolerance. x: ' + x [ i ] + '. Value: ' + v + '. Expected: ' + expected [ i ] + '. Tolerance: ' + tol + '.' ) ;
81
+ t . strictEqual ( ulpdiff ( v , expected [ i ] ) <= 1 , true , 'returns expected value' ) ;
85
82
}
86
83
t . end ( ) ;
87
84
} ) ;
88
85
89
86
tape ( 'the function accurately computes the natural exponential function for negative small numbers' , function test ( t ) {
90
87
var expected ;
91
- var delta ;
92
- var tol ;
93
88
var x ;
94
89
var v ;
95
90
var i ;
@@ -98,18 +93,16 @@ tape( 'the function accurately computes the natural exponential function for neg
98
93
expected = smallNegative . expected ;
99
94
100
95
for ( i = 0 ; i < x . length ; i ++ ) {
96
+ x [ i ] = f32 ( x [ i ] ) ;
97
+ expected [ i ] = f32 ( expected [ i ] ) ;
101
98
v = expf ( x [ i ] ) ;
102
- delta = absf ( v - expected [ i ] ) ;
103
- tol = 50 * EPS * absf ( expected [ i ] ) ;
104
- t . ok ( delta <= tol , 'within tolerance. x: ' + x [ i ] + '. Value: ' + v + '. Expected: ' + expected [ i ] + '. Tolerance: ' + tol + '.' ) ;
99
+ t . strictEqual ( ulpdiff ( v , expected [ i ] ) <= 1 , true , 'returns expected value' ) ;
105
100
}
106
101
t . end ( ) ;
107
102
} ) ;
108
103
109
104
tape ( 'the function accurately computes the natural exponential function for positive small numbers' , function test ( t ) {
110
105
var expected ;
111
- var delta ;
112
- var tol ;
113
106
var x ;
114
107
var v ;
115
108
var i ;
@@ -118,18 +111,16 @@ tape( 'the function accurately computes the natural exponential function for pos
118
111
expected = smallPositive . expected ;
119
112
120
113
for ( i = 0 ; i < x . length ; i ++ ) {
114
+ x [ i ] = f32 ( x [ i ] ) ;
115
+ expected [ i ] = f32 ( expected [ i ] ) ;
121
116
v = expf ( x [ i ] ) ;
122
- delta = absf ( v - expected [ i ] ) ;
123
- tol = 50 * EPS * absf ( expected [ i ] ) ;
124
- t . ok ( delta <= tol , 'within tolerance. x: ' + x [ i ] + '. Value: ' + v + '. Expected: ' + expected [ i ] + '. Tolerance: ' + tol + '.' ) ;
117
+ t . strictEqual ( ulpdiff ( v , expected [ i ] ) <= 1 , true , 'returns expected value' ) ;
125
118
}
126
119
t . end ( ) ;
127
120
} ) ;
128
121
129
122
tape ( 'the function accurately computes the natural exponential function for very small `x`' , function test ( t ) {
130
123
var expected ;
131
- var delta ;
132
- var tol ;
133
124
var x ;
134
125
var v ;
135
126
var i ;
@@ -138,28 +129,40 @@ tape( 'the function accurately computes the natural exponential function for ver
138
129
expected = tiny . expected ;
139
130
140
131
for ( i = 0 ; i < x . length ; i ++ ) {
132
+ x [ i ] = f32 ( x [ i ] ) ;
133
+ expected [ i ] = f32 ( expected [ i ] ) ;
141
134
v = expf ( x [ i ] ) ;
142
- delta = absf ( v - expected [ i ] ) ;
143
- tol = 50 * EPS * absf ( expected [ i ] ) ;
144
- t . ok ( delta <= tol , 'within tolerance. x: ' + x [ i ] + '. Value: ' + v + '. Expected: ' + expected [ i ] + '. Tolerance: ' + tol + '.' ) ;
135
+ t . strictEqual ( ulpdiff ( v , expected [ i ] ) <= 0 , true , 'returns expected value' ) ;
145
136
}
146
137
t . end ( ) ;
147
138
} ) ;
148
139
149
140
tape ( 'the function returns `0` if provided a `-infinity`' , function test ( t ) {
150
141
var val = expf ( NINF ) ;
151
- t . equal ( val , 0.0 , 'returns expected value' ) ;
142
+ t . strictEqual ( isPositiveZerof ( val ) , true , 'returns expected value' ) ;
152
143
t . end ( ) ;
153
144
} ) ;
154
145
155
146
tape ( 'the function returns `+infinity` if provided a `+infinity`' , function test ( t ) {
156
147
var val = expf ( PINF ) ;
157
- t . equal ( val , PINF , 'returns expected value' ) ;
148
+ t . strictEqual ( val , PINF , 'returns expected value' ) ;
158
149
t . end ( ) ;
159
150
} ) ;
160
151
161
152
tape ( 'the function returns `NaN` if provided a `NaN`' , function test ( t ) {
162
153
var val = expf ( NaN ) ;
163
- t . equal ( isnan ( val ) , true , 'returns expected value' ) ;
154
+ t . strictEqual ( isnanf ( val ) , true , 'returns expected value' ) ;
155
+ t . end ( ) ;
156
+ } ) ;
157
+
158
+ tape ( 'the function returns `1` if provided `+-0`' , function test ( t ) {
159
+ var val ;
160
+
161
+ val = expf ( f32 ( - 0.0 ) ) ;
162
+ t . strictEqual ( val , f32 ( 1.0 ) , 'returns expected value' ) ;
163
+
164
+ val = expf ( f32 ( + 0.0 ) ) ;
165
+ t . strictEqual ( val , f32 ( 1.0 ) , 'returns expected value' ) ;
166
+
164
167
t . end ( ) ;
165
168
} ) ;
0 commit comments