Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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.
*/

#ifndef STDLIB_MATH_BASE_SPECIAL_ERFINVF_H
#define STDLIB_MATH_BASE_SPECIAL_ERFINVF_H

/*
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.
*/
#ifdef __cplusplus
extern "C" {
#endif

/**
* Evaluates the inverse error function (single-precision).
*/
float stdlib_base_erfinvf( const float x );

#ifdef __cplusplus
}
#endif

#endif // !STDLIB_MATH_BASE_SPECIAL_ERFINVF_H
58 changes: 58 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/erfinvf/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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.
*/

'use strict';

/**
* Evaluate the inverse error function (single-precision).
*
* @module @stdlib/math/base/special/erfinvf
*
* @example
* var erfinvf = require( '@stdlib/math/base/special/erfinvf' );
*
* var y = erfinvf( 0.5 );
* // returns ~0.4769
*
* y = erfinvf( 0.8 );
* // returns ~0.9062
*
* y = erfinvf( 0.0 );
* // returns 0.0
*
* y = erfinvf( -0.0 );
* // returns -0.0
*
* y = erfinvf( -1.0 );
* // returns -Infinity
*
* y = erfinvf( 1.0 );
* // returns Infinity
*
* y = erfinvf( NaN );
* // returns NaN
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
166 changes: 166 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/erfinvf/lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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.
*
* ## Notice
*
* The original C++ code and copyright notice are from the [Boost library]{@link http://www.boost.org/doc/libs/1_48_0/boost/math/special_functions/detail/erf_inv.hpp}. This implementation follows the original, but has been modified for JavaScript.
*
* ```text
* (C) Copyright John Maddock 2006.
*
* Use, modification and distribution are subject to the
* Boost Software License, Version 1.0. (See accompanying file
* LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
* ```
*/

'use strict';

// MODULES //

var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var sqrtf = require( '@stdlib/math/base/special/sqrtf' );
var lnf = require( '@stdlib/math/base/special/lnf' );
var PINF = require( '@stdlib/constants/float64/pinf' );
var NINF = require( '@stdlib/constants/float64/ninf' );
var rationalFcnR1 = require( './rational_p1q1.js' );
var rationalFcnR2 = require( './rational_p2q2.js' );
var rationalFcnR3 = require( './rational_p3q3.js' );
var rationalFcnR4 = require( './rational_p4q4.js' );
var rationalFcnR5 = require( './rational_p5q5.js' );


// VARIABLES //

var Y1 = 8.91314744949340820313e-2;
var Y2 = 2.249481201171875;
var Y3 = 8.07220458984375e-1;
var Y4 = 9.3995571136474609375e-1;
var Y5 = 9.8362827301025390625e-1;


// MAIN //

/**
* Evaluates the inverse error function (single-precision).
*
* @param {number} x - input value
* @returns {number} function value
*
* @example
* var y = erfinvf( 0.5 );
* // returns ~0.4769
*
* @example
* var y = erfinvf( 0.8 );
* // returns ~0.9062
*
* @example
* var y = erfinvf( 0.0 );
* // returns 0.0
*
* @example
* var y = erfinvf( -0.0 );
* // returns -0.0
*
* @example
* var y = erfinvf( -1.0 );
* // returns -Infinity
*
* @example
* var y = erfinvf( 1.0 );
* // returns Infinity
*
* @example
* var y = erfinvf( NaN );
* // returns NaN
*/
function erfinvf( x ) {
var sign;
var ax;
var qs;
var q;
var g;
var r;

// Special case: NaN
if ( isnanf( x ) ) {
return NaN;
}
// Special case: 1
if ( x === 1.0 ) {
return PINF;
}
// Special case: -1
if ( x === -1.0 ) {
return NINF;
}
// Special case: +-0
if ( x === 0.0 ) {
return x;
}
// Special case: |x| > 1 (range error)
if ( x > 1.0 || x < -1.0 ) {
return NaN;
}
// Argument reduction (reduce to interval [0,1]). If `x` is negative, we can safely negate the value, taking advantage of the error function being an odd function; i.e., `erf(-x) = -erf(x)`.
if ( x < 0.0 ) {
sign = -1.0;
ax = -x;
} else {
sign = 1.0;
ax = x;
}
q = 1.0 - ax;

// |x| <= 0.5
if ( ax <= 0.5 ) {
g = ax * ( ax + 10.0 );
r = rationalFcnR1( ax );
return sign * ( (g*Y1) + (g*r) );
}
// 1-|x| >= 0.25
if ( q >= 0.25 ) {
g = sqrtf( -2.0 * lnf(q) );
q -= 0.25;
r = rationalFcnR2( q );
return sign * ( g / (Y2+r) );
}
q = sqrtf( -lnf( q ) );

// q < 3
if ( q < 3.0 ) {
qs = q - 1.125;
r = rationalFcnR3( qs );
return sign * ( (Y3*q) + (r*q) );
}
// q < 6
if ( q < 6.0 ) {
qs = q - 3.0;
r = rationalFcnR4( qs );
return sign * ( (Y4*q) + (r*q) );
}
// q < 18
qs = q - 6.0;
r = rationalFcnR5( qs );
return sign * ( (Y5*q) + (r*q) );
}


// EXPORTS //

module.exports = erfinvf;
42 changes: 42 additions & 0 deletions lib/node_modules/@stdlib/math/base/special/erfinvf/lib/native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2018 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.
*/

'use strict';

// MODULES //

var addon = require( './../src/addon.node' );


// MAIN //

/**
* Evaluates the inverse error function (single-precision).
*
* @private
* @param {number} x - input value
* @returns {number} evaluated inverse error function
*/
function erfinvf( x ) {
return addon( x );
}


// EXPORTS //

module.exports = erfinvf;
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2022 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.0005087819496582806;
}
if ( x < 0.0 ) {
ax = -x;
} else {
ax = x;
}
if ( ax <= 1.0 ) {
s1 = -0.0005087819496582806 + (x * (-0.008368748197417368 + (x * (0.03348066254097446 + (x * (-0.012692614766297404 + (x * (-0.03656379714117627 + (x * (0.02198786811111689 + (x * (0.008226878746769157 + (x * (-0.005387729650712429 + (x * (0.0 + (x * 0.0))))))))))))))))); // eslint-disable-line max-len
s2 = 1.0 + (x * (-0.9700050433032906 + (x * (-1.5657455823417585 + (x * (1.5622155839842302 + (x * (0.662328840472003 + (x * (-0.7122890234154284 + (x * (-0.05273963823400997 + (x * (0.07952836873415717 + (x * (-0.0023339375937419 + (x * 0.0008862163904564247))))))))))))))))); // eslint-disable-line max-len
} else {
x = 1.0 / x;
s1 = 0.0 + (x * (0.0 + (x * (-0.005387729650712429 + (x * (0.008226878746769157 + (x * (0.02198786811111689 + (x * (-0.03656379714117627 + (x * (-0.012692614766297404 + (x * (0.03348066254097446 + (x * (-0.008368748197417368 + (x * -0.0005087819496582806))))))))))))))))); // eslint-disable-line max-len
s2 = 0.0008862163904564247 + (x * (-0.0023339375937419 + (x * (0.07952836873415717 + (x * (-0.05273963823400997 + (x * (-0.7122890234154284 + (x * (0.662328840472003 + (x * (1.5622155839842302 + (x * (-1.5657455823417585 + (x * (-0.9700050433032906 + (x * 1.0))))))))))))))))); // eslint-disable-line max-len
}
return s1 / s2;
}


// EXPORTS //

module.exports = evalrational;
Loading
Loading