All files / math/base/special/sicif/lib assign.js

100% Statements 196/196
100% Branches 21/21
100% Functions 1/1
100% Lines 196/196

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 1973x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 6812x 6812x 6812x 6812x 6812x 6812x 6812x 6812x 6812x 6812x 6812x 6812x 2x 2x 2x 2x 6812x 3002x 3002x 6812x 3808x 3808x 6812x 2x 2x 2x 2x 6812x 1002x 4x 2x 2x 2x 2x 2x 2x 4x 4x 4x 4x 998x 998x 998x 6812x 3224x 3224x 3224x 3224x 488x 488x 3224x 2736x 2736x 2736x 3224x 3224x 1212x 1212x 3224x 3224x 3224x 3224x 3224x 3580x 3580x 3580x 6812x 1788x 1788x 3580x 3580x 3580x 3580x 3580x 6812x 3x 3x 3x 3x 3x  
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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, 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.
*
* ```text
* Copyright 1984, 1987, 1989 by Stephen L. Moshier
*
* 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.
*
* Stephen L. Moshier
* moshier@na-net.ornl.gov
* ```
*/
 
'use strict';
 
// MODULES //
 
var isInfinitef = require( '@stdlib/math/base/assert/is-infinitef' );
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
var cosf = require( '@stdlib/math/base/special/cosf' );
var sinf = require( '@stdlib/math/base/special/sinf' );
var lnf = require( '@stdlib/math/base/special/lnf' );
var f32 = require( '@stdlib/number/float64/base/to-float32' );
var HALF_PI = require( '@stdlib/constants/float32/half-pi' );
var GAMMA = require( '@stdlib/constants/float32/eulergamma' );
var NINF = require( '@stdlib/constants/float32/ninf' );
var polyvalFN4 = require( './polyval_fn4.js' );
var polyvalFD4 = require( './polyval_fd4.js' );
var polyvalFN8 = require( './polyval_fn8.js' );
var polyvalFD8 = require( './polyval_fd8.js' );
var polyvalGN4 = require( './polyval_gn4.js' );
var polyvalGD4 = require( './polyval_gd4.js' );
var polyvalGN8 = require( './polyval_gn8.js' );
var polyvalGD8 = require( './polyval_gd8.js' );
var polyvalSN = require( './polyval_sn.js' );
var polyvalSD = require( './polyval_sd.js' );
var polyvalCN = require( './polyval_cn.js' );
var polyvalCD = require( './polyval_cd.js' );
 
 
// VARIABLES //
 
var ZERO = f32( 0.0 );
var ONE = f32( 1.0 );
var FOUR = f32( 4.0 );
var EIGHT = f32( 8.0 );
var HUGE = f32( 1.0e9 );
 
 
// MAIN //
 
/**
* Computes the sine and cosine integrals in single-precision floating-point format and assigns results to a provided output array.
*
* ## Method
*
* -   The integrals are approximated by rational functions.
*
* -   For \\( x > 8 \\), auxiliary functions \\( f(x) \\) and \\( g(x) \\) are employed such that
*
*     ```tex
*     \operatorname{Ci}(x) = f(x) \sin(x) - g(x) \cos(x) \\
*     \operatorname{Si}(x) = \pi/2 - f(x) \cos(x) - g(x) \sin(x)
*     ```
*
* ## Notes
*
* -   Absolute error on test interval \\( \[0,50\] \\), except relative when greater than \\( 1 \\):
*
*     | arithmetic | function    | # trials | peak    | rms     |
*     |:----------:|:-----------:|:--------:|:-------:|:-------:|
*     | IEEE       | Si          | 30000    | 2.1e-7  | 4.3e-8  |
*     | IEEE       | Ci          | 30000    | 3.9e-7  | 2.2e-8  |
*
* @private
* @param {number} x - input value
* @param {Collection} out - output array
* @param {integer} stride - output array stride
* @param {NonNegativeInteger} offset - output array index offset
* @returns {Collection} output array
*
* @example
* var v = sicif( 3.0, [ 0.0, 0.0 ], 1, 0 );
* // returns [ ~1.849, ~0.12 ]
*
* @example
* var v = sicif( 0.0, [ 0.0, 0.0 ], 1, 0 );
* // returns [ 0.0, -Infinity  ]
*
* @example
* var v = sicif( -9.0, [ 0.0, 0.0 ], 1, 0 );
* // returns [ ~-1.665, ~0.055 ]
*
* @example
* var v = sicif( NaN, [ 0.0, 0.0 ], 1, 0 );
* // returns [ NaN, NaN ]
*/
function sicif( x, out, stride, offset ) {
	var sgn;
	var si;
	var ci;
	var c;
	var f;
	var g;
	var s;
	var z;
 
	x = f32( x );
	if ( isnanf( x ) ) {
		out[ offset ] = NaN;
		out[ offset + stride ] = NaN;
		return out;
	}
	if ( x < ZERO ) {
		sgn = -1;
		x = f32( -x );
	} else {
		sgn = 0;
	}
	if ( x === ZERO ) {
		out[ offset ] = ZERO;
		out[ offset + stride ] = NINF;
		return out;
	}
	if ( x > HUGE ) {
		if ( isInfinitef( x ) ) {
			if ( sgn === -1 ) {
				si = f32( -HALF_PI );
				ci = NaN;
			} else {
				si = f32( HALF_PI );
				ci = ZERO;
			}
			out[ offset ] = si;
			out[ offset + stride ] = ci;
			return out;
		}
		si = f32( HALF_PI - f32( cosf( x ) / x ) );
		ci = f32( sinf( x ) / x );
	}
	if ( x > FOUR ) {
		s = sinf( x );
		c = cosf( x );
		z = f32( ONE / f32( x*x ) );
		if ( x < EIGHT ) {
			f = f32( polyvalFN4( z ) / f32( x * polyvalFD4( z ) ) );
			g = f32( f32( z * polyvalGN4( z ) ) / polyvalGD4( z ) );
		} else {
			f = f32( polyvalFN8( z ) / f32( x * polyvalFD8( z ) ) );
			g = f32( f32( z * polyvalGN8( z ) ) / polyvalGD8( z ) );
		}
		si = f32( f32( HALF_PI - f32( f*c ) ) - f32( g*s ) );
		if ( sgn ) {
			si = f32( -si );
		}
		ci = f32( f32( f*s ) - f32( g*c ) );
		out[ offset ] = si;
		out[ offset + stride ] = ci;
		return out;
	}
	z = f32( x * x );
	s = f32( f32( x * polyvalSN( z ) ) / polyvalSD( z ) );
	c = f32( f32( z * polyvalCN( z ) ) / polyvalCD( z ) );
	if ( sgn ) {
		s = f32( -s );
	}
	si = s;
	ci = f32( f32( GAMMA + lnf( x ) ) + c ); // real part if x < 0
	out[ offset ] = si;
	out[ offset + stride ] = ci;
	return out;
}
 
 
// EXPORTS //
 
module.exports = sicif;