<commit_before>'use strict';

/*
* The original C code, long comment, copyright, license, and constants are from [Cephes]{@link http://www.netlib.org/cephes/}.
*
* The implementation follows the original, but has been modified for JavaScript.
*/

/*
* COPYRIGHT
*
* Cephes Math Library Release 2.1:  January, 1989
* Copyright 1984, 1987, 1989 by <NAME>
*
*
* LICENSE
*
* The README [file]{@link http://netlib.sandia.gov/cephes/} reads:
*   > Some software in this archive may be from the book _Methods and Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) or from the Cephes Mathematical Library, a commercial product. In either event, it is copyrighted by the author. What you see here may be used freely but it comes with no support or guarantee.
*   > <NAME>
*   > <EMAIL>
*/

// MODULES //

var sincos = require( '@stdlib/math/base/special/sincos' );
var abs = require( '@stdlib/math/base/special/abs' );
var evalrational = require( '@stdlib/math/base/tools/evalrational' ).factory;
var HALF_PI = require( '@stdlib/math/constants/float64-half-pi' );
var PI = require( '@stdlib/math/constants/float64-pi' );


// VARIABLES //

// S(x) for small x
var PS = [
	3.18016297876567817986E11,
	-4.42979518059697779103E10,
	2.54890880573376359104E9,
	-6.29741486205862506537E7,
	7.08840045257738576863E5,
	-2.99181919401019853726E3,
	0.0
];

var QS = [
	6.07366389490084639049E11,
	2.24411795645340920940E10,
	4.19320245898111231129E8,
	5.17343888770096400730E6,
	4.55847810806532581675E4,
	2.81376268889994315696E2,
	1.00000000000000000000E0
];

// Auxiliary function f(x)
var PF = [
	3.76329711269987889006E-20,
	1.34283276233062758925E-16,
	1.72010743268161828879E-13,
	1.02304514164907233465E-10,
	3.05568983790257605827E-8,
	4.63613749287867322088E-6,
	3.45017939782574027900E-4,
	1.15220955073585758835E-2,
	1.43407919780758885261E-1,
	4.21543555043677546506E-1,
	0.0
];

var QF = [
	1.25443237090011264384E-20,
	4.52001434074129701496E-17,
	5.88754533621578410010E-14,
	3.60140029589371370404E-11,
	1.12699224763999035261E-8,
	1.84627567348930545870E-6,
	1.55934409164153020873E-4,
	6.44051526508858611005E-3,
	1.16888925859191382142E-1,
	7.51586398353378947175E-1,
	1.00000000000000000000E0
];

// Auxiliary function g(x)
var PG = [
	1.86958710162783235106E-22,
	8.36354435630677421531E-19,
	1.37555460633261799868E-15,
	1.08268041139020870318E-12,
	4.45344415861750144738E-10,
	9.82852443688422223854E-8,
	1.15138826111884280931E-5,
	6.84079380915393090172E-4,
	1.87648584092575249293E-2,
	1.97102833525523411709E-1,
	5.04442073643383265887E-1,
	0.0
];

var QG = [
	1.86958710162783236342E-22,
	8.39158816283118707363E-19,
	1.38796531259578871258E-15,
	1.10273215066240270757E-12,
	4.60680728146520428211E-10,
	1.04314589657571990585E-7,
	1.27545075667729118702E-5,
	8.14679107184306179049E-4,
	2.53603741420338795122E-2,
	3.37748989120019970451E-1,
	1.47495759925128324529E0,
	1.00000000000000000000E0
];

var polyS = evalrational( PS, QS );
var polyF = evalrational( PF, QF );
var polyG = evalrational( PG, QG );

// Array for storing sincos evaluation:
var sc = [ 0.0, 0.0 ];


// MAIN //

/**
* Computes the Fresnel integral S(x).

* ## Method
*
* Evaluates the Fresnel integral
*
* ```tex
* \operatorname{S}(x) = \int_0^x \sin\left(\frac{\pi}{2} t^2\right)\,\mathrm{d}t
* ```
*
* The integral is evaluated by a power series for \\( x < 1 \\). For \\( x >= 1 \\) auxiliary functions \\( f(x) \\) and \\( g(x) \\) are employed such that
*
* ```tex
* \operatorname{S}(x) = \frac{1}{2} - f(x) \cos\left( \frac{\pi}{2} x^2 \right) - g(x) \sin\left( \frac{\pi}{2} x^2 \right).
* ```
*
* ## Notes
*
* * Relative error on test interval \\( \[0,10\] \\):
*
*   | arithmetic | function | # trials |  peak    | rms     |
*   |:----------:|:--------:|:--------:|:--------:|:-------:|
*   | IEEE       | S(x)     | 10000    |  2.0e-15 | 3.2e-16 |
*
* @private
* @param {number} x - input value
* @returns {number} S(x)
*
* @example
* var v = fresnels( 0.0 );
* // returns 0.0
*
* @example
* var v = fresnels( 1.0 );
* // returns ~0.438
*
* @example
* var v = fresnels( Infinity );
* // returns ~0.5
*
* @example
* var v = fresnels( -Infinity );
* // returns ~-0.5
*
* @example
* var v = fresnels( NaN );
* // returns NaN
*/
function fresnels( x ) {
	var x2;
	var xa;
	var S;
	var f;
	var g;
	var t;
	var u;

	xa = abs( x );
	x2 = xa * xa;
	if ( x2 < 2.5625 ) {
		t = x2 * x2;
		S = xa * x2 * polyS( t );
	} else if ( xa > 36974.0 ) {
		S = 0.5;
	} else {
		// Asymptotic power series auxiliary functions for large argument<commit_msg>Add colons<commit_after>'use strict';

/*
* The original C code, long comment, copyright, license, and constants are from [Cephes]{@link http://www.netlib.org/cephes/}.
*
* The implementation follows the original, but has been modified for JavaScript.
*/

/*
* COPYRIGHT
*
* Cephes Math Library Release 2.1:  January, 1989
* Copyright 1984, 1987, 1989 by <NAME>
*
*
* LICENSE
*
* The README [file]{@link http://netlib.sandia.gov/cephes/} reads:
*   > Some software in this archive may be from the book _Methods and Programs for Mathematical Functions_ (Prentice-Hall or Simon & Schuster International, 1989) or from the Cephes Mathematical Library, a commercial product. In either event, it is copyrighted by the author. What you see here may be used freely but it comes with no support or guarantee.
*   > <NAME>
*   > <EMAIL>
*/

// MODULES //

var sincos = require( '@stdlib/math/base/special/sincos' );
var abs = require( '@stdlib/math/base/special/abs' );
var evalrational = require( '@stdlib/math/base/tools/evalrational' ).factory;
var HALF_PI = require( '@stdlib/math/constants/float64-half-pi' );
var PI = require( '@stdlib/math/constants/float64-pi' );


// VARIABLES //

// S(x) for small x:
var PS = [
	3.18016297876567817986E11,
	-4.42979518059697779103E10,
	2.54890880573376359104E9,
	-6.29741486205862506537E7,
	7.08840045257738576863E5,
	-2.99181919401019853726E3,
	0.0
];

var QS = [
	6.07366389490084639049E11,
	2.24411795645340920940E10,
	4.19320245898111231129E8,
	5.17343888770096400730E6,
	4.55847810806532581675E4,
	2.81376268889994315696E2,
	1.00000000000000000000E0
];

// Auxiliary function f(x):
var PF = [
	3.76329711269987889006E-20,
	1.34283276233062758925E-16,
	1.72010743268161828879E-13,
	1.02304514164907233465E-10,
	3.05568983790257605827E-8,
	4.63613749287867322088E-6,
	3.45017939782574027900E-4,
	1.15220955073585758835E-2,
	1.43407919780758885261E-1,
	4.21543555043677546506E-1,
	0.0
];

var QF = [
	1.25443237090011264384E-20,
	4.52001434074129701496E-17,
	5.88754533621578410010E-14,
	3.60140029589371370404E-11,
	1.12699224763999035261E-8,
	1.84627567348930545870E-6,
	1.55934409164153020873E-4,
	6.44051526508858611005E-3,
	1.16888925859191382142E-1,
	7.51586398353378947175E-1,
	1.00000000000000000000E0
];

// Auxiliary function g(x):
var PG = [
	1.86958710162783235106E-22,
	8.36354435630677421531E-19,
	1.37555460633261799868E-15,
	1.08268041139020870318E-12,
	4.45344415861750144738E-10,
	9.82852443688422223854E-8,
	1.15138826111884280931E-5,
	6.84079380915393090172E-4,
	1.87648584092575249293E-2,
	1.97102833525523411709E-1,
	5.04442073643383265887E-1,
	0.0
];

var QG = [
	1.86958710162783236342E-22,
	8.39158816283118707363E-19,
	1.38796531259578871258E-15,
	1.10273215066240270757E-12,
	4.60680728146520428211E-10,
	1.04314589657571990585E-7,
	1.27545075667729118702E-5,
	8.14679107184306179049E-4,
	2.53603741420338795122E-2,
	3.37748989120019970451E-1,
	1.47495759925128324529E0,
	1.00000000000000000000E0
];

var polyS = evalrational( PS, QS );
var polyF = evalrational( PF, QF );
var polyG = evalrational( PG, QG );

// Array for storing sincos evaluation:
var sc = [ 0.0, 0.0 ];


// MAIN //

/**
* Computes the Fresnel integral S(x).

* ## Method
*
* Evaluates the Fresnel integral
*
* ```tex
* \operatorname{S}(x) = \int_0^x \sin\left(\frac{\pi}{2} t^2\right)\,\mathrm{d}t
* ```
*
* The integral is evaluated by a power series for \\( x < 1 \\). For \\( x >= 1 \\) auxiliary functions \\( f(x) \\) and \\( g(x) \\) are employed such that
*
* ```tex
* \operatorname{S}(x) = \frac{1}{2} - f(x) \cos\left( \frac{\pi}{2} x^2 \right) - g(x) \sin\left( \frac{\pi}{2} x^2 \right).
* ```
*
* ## Notes
*
* * Relative error on test interval \\( \[0,10\] \\):
*
*   | arithmetic | function | # trials |  peak    | rms     |
*   |:----------:|:--------:|:--------:|:--------:|:-------:|
*   | IEEE       | S(x)     | 10000    |  2.0e-15 | 3.2e-16 |
*
* @private
* @param {number} x - input value
* @returns {number} S(x)
*
* @example
* var v = fresnels( 0.0 );
* // returns 0.0
*
* @example
* var v = fresnels( 1.0 );
* // returns ~0.438
*
* @example
* var v = fresnels( Infinity );
* // returns ~0.5
*
* @example
* var v = fresnels( -Infinity );
* // returns ~-0.5
*
* @example
* var v = fresnels( NaN );
* // returns NaN
*/
function fresnels( x ) {
	var x2;
	var xa;
	var S;
	var f;
	var g;
	var t;
	var u;

	xa = abs( x );
	x2 = xa * xa;
	if ( x2 < 2.5625 ) {
		t = x2 * x2;
		S = xa * x2 * polyS( t );
	} else if ( xa > 36974.0 ) {
		S = 0.5;
	} else {
		// Asymptotic power series auxiliary functions for large arguments...
{'fraction_non_alphanumeric': 0.16043715846994536, 'fraction_numerical': 0.29989071038251364, 'mean_word_length': 3.5101034992607194, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4362805', 'n_tokens_mistral': 5621, 'n_tokens_neox': 4070, 'n_words': 792}