Skip to content

Commit 5b2a045

Browse files
committed
chore: changes according to code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5dccdd0 commit 5b2a045

3 files changed

Lines changed: 35 additions & 52 deletions

File tree

lib/node_modules/@stdlib/math/base/special/erfcinvf/lib/main.js

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ var Y2 = 2.249481201171875;
5353
var Y3 = 8.07220458984375e-1;
5454
var Y4 = 9.3995571136474609375e-1;
5555
var Y5 = 9.8362827301025390625e-1;
56+
var ZERO = f32( 0.0 );
57+
var ONE = f32( 1.0 );
58+
var TWO = f32( 2.0 );
59+
var NEG_ONE = f32( -1.0 );
60+
var HALF = f32( 0.5 );
61+
var QUARTER = f32( 0.25 );
62+
var TEN = f32( 10.0 );
63+
var ONE_TWO_FIVE = f32( 1.125 );
64+
var THREE = f32( 3.0 );
65+
var SIX = f32( 6.0 );
5666

5767

5868
// MAIN //
@@ -164,61 +174,61 @@ function erfcinvf( x ) {
164174
return NaN;
165175
}
166176
// Special case: 0
167-
if ( x === 0.0 ) {
177+
if ( x === ZERO ) {
168178
return PINF;
169179
}
170180
// Special case: 2
171-
if ( x === 2.0 ) {
181+
if ( x === TWO ) {
172182
return NINF;
173183
}
174184
// Special case: 1
175-
if ( x === 1.0 ) {
185+
if ( x === ONE ) {
176186
return 0.0;
177187
}
178-
if ( x > 2.0 || x < 0.0 ) {
188+
if ( x > TWO || x < ZERO ) {
179189
return NaN;
180190
}
181191
// Argument reduction (reduce to interval [0,1]). If `x` is outside [0,1], we can take advantage of the complementary error function reflection formula: `erfc(-z) = 2 - erfc(z)`, by negating the result once finished.
182-
if ( x > 1.0 ) {
183-
sign = -1.0;
184-
q = f32( 2.0 - x );
192+
if ( x > ONE ) {
193+
sign = NEG_ONE;
194+
q = f32( TWO - x );
185195
} else {
186-
sign = 1.0;
196+
sign = ONE;
187197
q = x;
188198
}
189-
x = f32( 1.0 - q );
199+
x = f32( ONE - q );
190200

191201
// x = 1-q <= 0.5
192-
if ( x <= 0.5 ) {
193-
g = f32( x * ( x + 10.0 ) );
202+
if ( x <= HALF ) {
203+
g = f32( x * ( x + TEN ) );
194204
r = rationalFcnR1( x );
195-
return f32( sign * ( (g*Y1) + (g*r) ) );
205+
return f32( sign * ( f32(g*Y1) + f32(g*r) ) );
196206
}
197207
// q >= 0.25
198-
if ( q >= 0.25 ) {
208+
if ( q >= QUARTER ) {
199209
g = sqrtf( f32( -2.0 * lnf( q ) ) );
200-
q = f32( q - 0.25 );
210+
q = f32( q - QUARTER );
201211
r = rationalFcnR2( q );
202-
return f32( sign * ( g / (Y2+r) ) );
212+
return f32( sign * ( g / f32(Y2+r) ) );
203213
}
204214
q = sqrtf( f32( -lnf( q ) ) );
205215

206216
// q < 3
207-
if ( q < 3.0 ) {
208-
qs = f32( q - 1.125 );
217+
if ( q < THREE ) {
218+
qs = f32( q - ONE_TWO_FIVE );
209219
r = rationalFcnR3( qs );
210-
return f32( sign * ( (Y3*q) + (r*q) ) );
220+
return f32( sign * ( f32(Y3*q) + f32(r*q) ) );
211221
}
212222
// q < 6
213-
if ( q < 6.0 ) {
214-
qs = f32( q - 3.0 );
223+
if ( q < SIX ) {
224+
qs = f32( q - THREE );
215225
r = rationalFcnR4( qs );
216-
return f32( sign * ( (Y4*q) + (r*q) ) );
226+
return f32( sign * ( f32(Y4*q) + f32(r*q) ) );
217227
}
218228
// q < 18
219-
qs = f32( q - 6.0 );
229+
qs = f32( q - SIX );
220230
r = rationalFcnR5( qs );
221-
return f32( sign * ( (Y5*q) + (r*q) ) );
231+
return f32( sign * ( f32(Y5*q) + f32(r*q) ) );
222232
}
223233

224234

lib/node_modules/@stdlib/math/base/special/erfcinvf/test/test.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
113113
for ( i = 0; i < x.length; i++ ) {
114114
y = erfcinvf( x[ i ] );
115115
e = f32( expected[ i ] );
116-
if ( e === null ) {
117-
e = NINF;
118-
}
119116
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
120117
}
121118
t.end();
@@ -136,9 +133,6 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
136133
for ( i = 0; i < x.length; i++ ) {
137134
y = erfcinvf( x[ i ] );
138135
e = f32( expected[ i ] );
139-
if ( e === null ) {
140-
e = NINF;
141-
}
142136
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
143137
}
144138
t.end();
@@ -159,9 +153,6 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
159153
for ( i = 0; i < x.length; i++ ) {
160154
y = erfcinvf( x[ i ] );
161155
e = f32( expected[ i ] );
162-
if ( e === null ) {
163-
e = NINF;
164-
}
165156
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
166157
}
167158
t.end();
@@ -182,9 +173,6 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
182173
for ( i = 0; i < x.length; i++ ) {
183174
y = erfcinvf( x[ i ] );
184175
e = f32( expected[ i ] );
185-
if ( e === null ) {
186-
e = NINF;
187-
}
188176
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
189177
}
190178
t.end();
@@ -205,9 +193,6 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
205193
for ( i = 0; i < x.length; i++ ) {
206194
y = erfcinvf( x[ i ] );
207195
e = f32( expected[ i ] );
208-
if ( e === null ) {
209-
e = NINF;
210-
}
211196
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
212197
}
213198
t.end();
@@ -221,16 +206,13 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
221206
var i;
222207
var e;
223208

224-
ulps = 23;
209+
ulps = 24;
225210
expected = x6.expected;
226211
x = x6.x;
227212

228213
for ( i = 0; i < x.length; i++ ) {
229214
y = erfcinvf( x[ i ] );
230215
e = f32( expected[ i ] );
231-
if ( e === null ) {
232-
e = NINF;
233-
}
234216
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
235217
}
236218
t.end();
@@ -244,16 +226,13 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
244226
var i;
245227
var e;
246228

247-
ulps = 23;
229+
ulps = 24;
248230
expected = x7.expected;
249231
x = x7.x;
250232

251233
for ( i = 0; i < x.length; i++ ) {
252234
y = erfcinvf( x[ i ] );
253235
e = f32( expected[ i ] );
254-
if ( e === null ) {
255-
e = NINF;
256-
}
257236
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
258237
}
259238
t.end();

lib/node_modules/@stdlib/math/base/special/erfcinvf/test/test.native.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,6 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
203203
for ( i = 0; i < x.length; i++ ) {
204204
y = erfcinvf( x[ i ] );
205205
e = f32( expected[ i ] );
206-
if ( e === null ) {
207-
e = NINF;
208-
}
209206
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
210207
}
211208
t.end();
@@ -246,9 +243,6 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
246243
for ( i = 0; i < x.length; i++ ) {
247244
y = erfcinvf( x[ i ] );
248245
e = f32( expected[ i ] );
249-
if ( e === null ) {
250-
e = NINF;
251-
}
252246
t.strictEqual( isAlmostSameValue( y, e, ulps ), true, 'within '+ulps+' ULPs. x: '+x[i]+'. y: '+y+'. E: '+e );
253247
}
254248
t.end();

0 commit comments

Comments
 (0)