Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/erfcinv/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var rationalFcnR2 = require( './rational_p2q2.js' );
var rationalFcnR3 = require( './rational_p3q3.js' );
var rationalFcnR4 = require( './rational_p4q4.js' );
var rationalFcnR5 = require( './rational_p5q5.js' );
var rationalFcnR6 = require( './rational_p6q6.js' );


// VARIABLES //
Expand All @@ -52,6 +53,7 @@ var Y2 = 2.249481201171875;
var Y3 = 8.07220458984375e-1;
var Y4 = 9.3995571136474609375e-1;
var Y5 = 9.8362827301025390625e-1;
var Y6 = 9.9714565277099609375e-1;


// MAIN //
Expand Down Expand Up @@ -214,9 +216,15 @@ function erfcinv( x ) {
return sign * ( (Y4*q) + (r*q) );
}
// q < 18
qs = q - 6.0;
r = rationalFcnR5( qs );
return sign * ( (Y5*q) + (r*q) );
if ( q < 18.0 ) {
qs = q - 6.0;
r = rationalFcnR5( qs );
return sign * ( (Y5*q) + (r*q) );
}
// q < 44 (the smallest double gives `q = 27.28...`)
qs = q - 18.0;
r = rationalFcnR6( qs );
return sign * ( (Y6*q) + (r*q) );
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* This is a generated file. Do not edit directly. */
'use strict';

// MAIN //

/**
* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)).
*
* ## Notes
*
* - Coefficients should be sorted in ascending degree.
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
*
* @private
* @param {number} x - value at which to evaluate the rational function
* @returns {number} evaluated rational function
*/
function evalrational( x ) {
var ax;
var s1;
var s2;
if ( x === 0.0 ) {
return -0.002497821279189813;
}
if ( x < 0.0 ) {
ax = -x;
} else {
ax = x;
}
if ( ax <= 1.0 ) {
s1 = -0.002497821279189813 + (x * (-0.00000779190719229054 + (x * (0.000025472303741302746 + (x * (0.0000016239777734251093 + (x * (3.963410113048012e-8 + (x * (4.116328311909442e-10 + (x * (1.4559628671867504e-12 + (x * -1.1676501239718427e-18))))))))))))); // eslint-disable-line max-len
s2 = 1.0 + (x * (0.2071231122144225 + (x * (0.01694108381209759 + (x * (0.0006905382656226846 + (x * (0.000014500735981823264 + (x * (1.4443775662814415e-7 + (x * (5.097612765997785e-10 + (x * 0.0))))))))))))); // eslint-disable-line max-len
} else {
x = 1.0 / x;
s1 = -1.1676501239718427e-18 + (x * (1.4559628671867504e-12 + (x * (4.116328311909442e-10 + (x * (3.963410113048012e-8 + (x * (0.0000016239777734251093 + (x * (0.000025472303741302746 + (x * (-0.00000779190719229054 + (x * -0.002497821279189813))))))))))))); // eslint-disable-line max-len
s2 = 0.0 + (x * (5.097612765997785e-10 + (x * (1.4443775662814415e-7 + (x * (0.000014500735981823264 + (x * (0.0006905382656226846 + (x * (0.01694108381209759 + (x * (0.2071231122144225 + (x * 1.0))))))))))))); // eslint-disable-line max-len
}
return s1 / s2;
}


// EXPORTS //

module.exports = evalrational;
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

// Polynomial coefficients ordered in ascending degree...

// Coefficients for erfinv on [0, 0.5]:

Check warning on line 42 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "erfinv"
var P1 = [
-5.08781949658280665617e-4,
-8.36874819741736770379e-3,
Expand All @@ -65,7 +65,7 @@
8.86216390456424707504e-4
];

// Coefficients for erfinv for 0.5 > 1-x >= 0:

Check warning on line 68 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "erfinv"
var P2 = [
-2.02433508355938759655e-1,
1.05264680699391713268e-1,
Expand All @@ -89,7 +89,7 @@
1.72114765761200282724
];

// Coefficients for erfinv for sqrt( -log(1-x) ):

Check warning on line 92 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "erfinv"
var P3 = [
-1.31102781679951906451e-1,
-1.63794047193317060787e-1,
Expand Down Expand Up @@ -163,6 +163,27 @@
0.0
];

var P6 = [
-2.4978212791898131227e-3,
-7.79190719229053954292e-6,
2.54723037413027451751e-5,
1.62397777342510920873e-6,
3.96341011304801168516e-8,
4.11632831190944208473e-10,
1.45596286718675035587e-12,
-1.16765012397184275695e-18
];
var Q6 = [
1.0,
2.07123112214422517181e-1,
1.69410838120975906478e-2,
6.90538265622684595676e-4,
1.45007359818232637924e-5,
1.44437756628144157666e-7,
5.09761276599778486139e-10,
0.0
];

// Header to add to output files:
var header = licenseHeader( 'Apache-2.0', 'js', {
'year': currentYear(),
Expand Down Expand Up @@ -218,31 +239,35 @@

fpath = resolve( __dirname, '..', 'lib', 'rational_p1q1.js' );
str = header + compile( P1, Q1 );
writeFileSync( fpath, str, opts );

Check warning on line 242 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected sync method: 'writeFileSync'

fpath = resolve( __dirname, '..', 'lib', 'rational_p2q2.js' );
str = header + compile( P2, Q2 );
writeFileSync( fpath, str, opts );

Check warning on line 246 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected sync method: 'writeFileSync'

fpath = resolve( __dirname, '..', 'lib', 'rational_p3q3.js' );
str = header + compile( P3, Q3 );
writeFileSync( fpath, str, opts );

Check warning on line 250 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected sync method: 'writeFileSync'

fpath = resolve( __dirname, '..', 'lib', 'rational_p4q4.js' );
str = header + compile( P4, Q4 );
writeFileSync( fpath, str, opts );

Check warning on line 254 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected sync method: 'writeFileSync'

fpath = resolve( __dirname, '..', 'lib', 'rational_p5q5.js' );
str = header + compile( P5, Q5 );
writeFileSync( fpath, str, opts );

Check warning on line 258 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected sync method: 'writeFileSync'

fpath = resolve( __dirname, '..', 'lib', 'rational_p6q6.js' );
str = header + compile( P6, Q6 );
writeFileSync( fpath, str, opts );

Check warning on line 262 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected sync method: 'writeFileSync'

copts = {
'dtype': 'double',
'name': ''
};

fpath = resolve( __dirname, '..', 'src', 'main.c' );
file = readFileSync( fpath, opts );

Check warning on line 270 in lib/node_modules/@stdlib/math/base/special/erfcinv/scripts/evalrational.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected sync method: 'readFileSync'

copts.name = 'rational_p1q1';
str = compileC( P1, Q1, copts );
Expand All @@ -264,6 +289,10 @@
str = compileC( P5, Q5, copts );
file = insert( file, copts.name, str );

copts.name = 'rational_p6q6';
str = compileC( P6, Q6, copts );
file = insert( file, copts.name, str );

writeFileSync( fpath, file, opts );
}

Expand Down
54 changes: 51 additions & 3 deletions lib/node_modules/@stdlib/math/base/special/erfcinv/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static const double Y2 = 2.249481201171875;
static const double Y3 = 8.07220458984375e-1;
static const double Y4 = 9.3995571136474609375e-1;
static const double Y5 = 9.8362827301025390625e-1;
static const double Y6 = 9.9714565277099609375e-1;

/* Begin auto-generated functions. The following functions are auto-generated. Do not edit directly. */

Expand Down Expand Up @@ -251,6 +252,47 @@ static double rational_p5q5( const double x ) {

// END: rational_p5q5

// BEGIN: rational_p6q6

/**
* Evaluates a rational function (i.e., the ratio of two polynomials described by the coefficients stored in \\(P\\) and \\(Q\\)).
*
* ## Notes
*
* - Coefficients should be sorted in ascending degree.
* - The implementation uses [Horner's rule][horners-method] for efficient computation.
*
* [horners-method]: https://en.wikipedia.org/wiki/Horner%27s_method
*
* @param x value at which to evaluate the rational function
* @return evaluated rational function
*/
static double rational_p6q6( const double x ) {
double ax;
double ix;
double s1;
double s2;
if ( x == 0.0 ) {
return -0.002497821279189813;
}
if ( x < 0.0 ) {
ax = -x;
} else {
ax = x;
}
if ( ax <= 1.0 ) {
s1 = -0.002497821279189813 + (x * (-0.00000779190719229054 + (x * (0.000025472303741302746 + (x * (0.0000016239777734251093 + (x * (3.963410113048012e-8 + (x * (4.116328311909442e-10 + (x * (1.4559628671867504e-12 + (x * -1.1676501239718427e-18)))))))))))));
s2 = 1.0 + (x * (0.2071231122144225 + (x * (0.01694108381209759 + (x * (0.0006905382656226846 + (x * (0.000014500735981823264 + (x * (1.4443775662814415e-7 + (x * (5.097612765997785e-10 + (x * 0.0)))))))))))));
} else {
ix = 1.0 / x;
s1 = -1.1676501239718427e-18 + (ix * (1.4559628671867504e-12 + (ix * (4.116328311909442e-10 + (ix * (3.963410113048012e-8 + (ix * (0.0000016239777734251093 + (ix * (0.000025472303741302746 + (ix * (-0.00000779190719229054 + (ix * -0.002497821279189813)))))))))))));
s2 = 0.0 + (ix * (5.097612765997785e-10 + (ix * (1.4443775662814415e-7 + (ix * (0.000014500735981823264 + (ix * (0.0006905382656226846 + (ix * (0.01694108381209759 + (ix * (0.2071231122144225 + (ix * 1.0)))))))))))));
}
return s1 / s2;
}

// END: rational_p6q6

/* End auto-generated functions. */

/**
Expand Down Expand Up @@ -396,7 +438,13 @@ double stdlib_base_erfcinv( const double x ) {
return sign * ( ( Y4 * q ) + ( r * q ) );
}
// q < 18
qs = q - 6.0;
r = rational_p5q5( qs );
return sign * ( ( Y5 * q ) + ( r * q ) );
if ( q < 18.0 ) {
qs = q - 6.0;
r = rational_p5q5( qs );
return sign * ( ( Y5 * q ) + ( r * q ) );
}
// q < 44 (the smallest double gives `q = 27.28...`)
qs = q - 18.0;
r = rational_p6q6( qs );
return sign * ( ( Y6 * q ) + ( r * q ) );
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import JSON
using SpecialFunctions

"""
gen( x, filepath )
gen( x, filepath )

Generate fixture data and write to file.

Expand Down Expand Up @@ -53,6 +53,35 @@ function gen( x, filepath )
close( outfile );
end

"""
gen_tiny( x, filepath )

Generate fixture data for tiny `x` in extended precision and write to file.

# Arguments

* `x`: domain
* `filepath::AbstractString`: filepath of the output file
"""
function gen_tiny( x, filepath )
y = Array{Float64}( undef, length(x) );
setprecision( BigFloat, 2048 ) do
for i in eachindex(x)
y[i] = Float64( erfcinv( BigFloat( x[i] ) ) );
end
end

data = Dict([
("x", x),
("expected", y)
]);

outfile = open( filepath, "w" );
write( outfile, JSON.json(data) );
write( outfile, "\n" );
close( outfile );
end

# Get the filename:
file = @__FILE__;

Expand Down Expand Up @@ -93,3 +122,8 @@ gen( x, out );
x = range( 1.9999999999999998, stop = 2, length = 500 );
out = joinpath( dir, "x_1.9999..8_2.json" );
gen( x, out );

# Tiny values, `sqrt(-ln(x)) >= 6` (log-spaced down to the smallest subnormal):
x = vcat( exp10.( range( -15.0, stop = -323.0, length = 1000 ) ), [ 5.0e-324 ] );
out = joinpath( dir, "x_tiny.json" );
gen_tiny( x, out );

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/erfcinv/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var x4 = require( './fixtures/julia/x_1.75_1.9998.json' );
var x5 = require( './fixtures/julia/x_0.0002_0.25.json' );
var x6 = require( './fixtures/julia/x_1.9998_1.9999..8.json' );
var x7 = require( './fixtures/julia/x_1.9999..8_2.json' );
var x8 = require( './fixtures/julia/x_tiny.json' );


// TESTS //
Expand Down Expand Up @@ -200,3 +201,18 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
}
t.end();
});

tape( 'the function evaluates the inverse complementary error function for tiny `x`', function test( t ) {
var expected;
var x;
var y;
var i;

expected = x8.expected;
x = x8.x;
for ( i = 0; i < x.length; i++ ) {
y = erfcinv( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'x: '+x[i]+'. y: '+y+'. E: '+expected[i] );
}
t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var x4 = require( './fixtures/julia/x_1.75_1.9998.json' );
var x5 = require( './fixtures/julia/x_0.0002_0.25.json' );
var x6 = require( './fixtures/julia/x_1.9998_1.9999..8.json' );
var x7 = require( './fixtures/julia/x_1.9999..8_2.json' );
var x8 = require( './fixtures/julia/x_tiny.json' );


// VARIABLES //
Expand Down Expand Up @@ -209,3 +210,18 @@ tape( 'the function evaluates the inverse complementary error function for `x` o
}
t.end();
});

tape( 'the function evaluates the inverse complementary error function for tiny `x`', opts, function test( t ) {
var expected;
var x;
var y;
var i;

expected = x8.expected;
x = x8.x;
for ( i = 0; i < x.length; i++ ) {
y = erfcinv( x[i] );
t.strictEqual( isAlmostSameValue( y, expected[ i ], 2 ), true, 'x: '+x[i]+'. y: '+y+'. E: '+expected[i] );
}
t.end();
});
Loading