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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | 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 3x 3x 3x 48009x 48009x 48009x 48009x 48009x 48009x 48009x 48009x 48009x 48009x 48009x 16x 16x 4x 4x 4x 4x 4x 4x 12x 12x 47993x 48009x 67x 67x 35x 19x 19x 19x 19x 27x 16x 16x 16x 16x 16x 67x 32x 16x 16x 16x 16x 32x 32x 32x 67x 67x 47926x 48009x 64x 64x 32x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 32x 16x 16x 16x 16x 64x 64x 47862x 48009x 6x 6x 6x 6x 47856x 47856x 47856x 47856x 47856x 47856x 47856x 48009x 11604x 48009x 12084x 12084x 12084x 12084x 48009x 12084x 12084x 12084x 48009x 12084x 12084x 12084x 12084x 48009x 48009x 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 following copyright and license were part of the original implementation available as part of FreeBSD [k_sin.c]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/k_sin.c} and [k_cos.c]{@link https://svnweb.freebsd.org/base/release/9.3.0/lib/msun/src/k_cos.c}. The implementation follows the original sine and cosine kernels, but has been modified for JavaScript and combined into a single function. * * ```text * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ``` */ 'use strict'; // MODULES // var toWordf = require( '@stdlib/number/float32/base/to-word' ); var rempio2f = require( '@stdlib/math/base/special/rempio2f' ); var f32 = require( '@stdlib/number/float64/base/to-float32' ); var FLOAT32_ABS_MASK = require( '@stdlib/constants/float32/abs-mask' ); var FLOAT32_EXPONENT_MASK = require( '@stdlib/constants/float32/exponent-mask' ); var FLOAT64_HALF_PI = require( '@stdlib/constants/float64/half-pi' ); var kernelSincosf = require( '@stdlib/math/base/special/kernel-sincosf' ).assign; // VARIABLES // // PI/4 = 0.7853981256484985 => 0 01111110 10010010000111111011010 => 0x3f490fda = 1061752768 var PIO4_WORD = 0x3f490fda|0; // asm type annotation // 3*PI/4 = 2.356194257736206 => 0 10000000 00101101100101111100011 => 0x4016cbe3 = 1075235811 var THREE_PIO4_WORD = 0x4016cbe3|0; // asm type annotation // 5*PI/4 = 3.9269907474517822 => 0 10000000 11110110101001111010001 => 0x407b53d1 = 1081824209 var FIVE_PIO4_WORD = 0x407b53d1|0; // asm type annotation // 7*PI/4 = 5.497786998748779 => 0 10000001 01011111110110111011111 => 0x40afeddf = 1085271519 var SEVEN_PIO4_WORD = 0x40afeddf|0; // asm type annotation // 9*PI/4 = 7.068583011627197 => 0 10000001 11000100011000111010101 => 0x40e231d5 = 1088565717 var NINE_PIO4_WORD = 0x40e231d5|0; // asm type annotation // 2^-12 = 0.000244140625 => 0 01110011 00000000000000000000000 => 0x39800000 = 964689920 var SMALL_WORD = 0x39800000|0; // asm type annotation // Small multiples of PI/2 in double-precision floating-point format: var PIO2 = FLOAT64_HALF_PI; // 0x3FF921FB, 0x54442D18 var PI = 2.0 * FLOAT64_HALF_PI; // 0x400921FB, 0x54442D18 var THREE_PIO2 = 3.0 * FLOAT64_HALF_PI; // 0x4012D97C, 0x7F3321D2 var TWO_PI = 4.0 * FLOAT64_HALF_PI; // 0x401921FB, 0x54442D18 // Array for storing the remainder element: var Y = [ 0.0 ]; // MAIN // /** * Simultaneously computes the sine and cosine of a single-precision floating-point number (in radians) and assigns the results to a provided output array. * * ## Method * * - Let \\(S\\), \\(C\\), and \\(T\\) denote the \\(\sin\\), \\(\cos\\) and \\(\tan\\), respectively, on \\(\[-\pi/4, +\pi/4\]\\). * * - Reduce the argument \\(x\\) to \\(y = x-k\pi/2\\) in \\(\[-\pi/4, +\pi/4\]\\), and let \\(n = k \mod 4\\). * * - We have * * | n | sin(x) | cos(x) | tan(x) | * | - | ------ | ------ | ------ | * | 0 | S | C | T | * | 1 | C | -S | -1/T | * | 2 | -S | -C | T | * | 3 | -C | S | -1/T | * * @private * @param {number} x - input value (in radians) * @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 = sincosf( 0.0, [ 0.0, 0.0 ], 1, 0 ); * // returns [ ~0.0, ~1.0 ] * * @example * var v = sincosf( 3.141592653589793/2.0, [ 0.0, 0.0 ], 1, 0 ); * // returns [ ~1.0, ~0.0 ] * * @example * var v = sincosf( -3.141592653589793/6.0, [ 0.0, 0.0 ], 1, 0 ); * // returns [ ~-0.5, ~0.866 ] * * @example * var v = sincosf( NaN, [ 0.0, 0.0 ], 1, 0 ); * // returns [ NaN, NaN ] */ function sincosf( x, out, stride, offset ) { var tmp; var hx; var ix; var n; hx = toWordf( f32( x ) ) |0; // asm type annotation ix = (hx & FLOAT32_ABS_MASK)|0; // asm type annotation // Case: |x| ~<= π/4 if ( ix <= PIO4_WORD ) { // Case: |x| < 2^-12 if ( ix < SMALL_WORD ) { if ( (x|0) === 0 ) { out[ offset ] = f32( x ); out[ offset+stride ] = f32( 1.0 ); return out; } } return kernelSincosf( x, out, stride, offset ); } // Case: |x| ~<= 5π/4 if ( ix <= FIVE_PIO4_WORD ) { // Case: |x| ~<= 3π/4 if ( ix <= THREE_PIO4_WORD ) { if ( hx > 0 ) { kernelSincosf( x - PIO2, out, stride, offset ); tmp = f32( -out[ offset ] ); out[ offset ] = out[ offset+stride ]; out[ offset+stride ] = tmp; } else { kernelSincosf( x + PIO2, out, stride, offset ); tmp = f32( -out[ offset+stride ] ); out[ offset+stride ] = out[ offset ]; out[ offset ] = tmp; } } else { if ( hx > 0 ) { kernelSincosf( x - PI, out, stride, offset ); } else { kernelSincosf( x + PI, out, stride, offset ); } out[ offset ] = f32( -out[ offset ] ); out[ offset+stride ] = f32( -out[ offset+stride ] ); } return out; } // Case: |x| ~<= 9π/4 if ( ix <= NINE_PIO4_WORD ) { // Case: |x| ~<= 7π/4 if ( ix <= SEVEN_PIO4_WORD ) { if ( hx > 0 ) { kernelSincosf( x - THREE_PIO2, out, stride, offset ); tmp = f32( -out[ offset+stride ] ); out[ offset+stride ] = out[ offset ]; out[ offset ] = tmp; } else { kernelSincosf( x + THREE_PIO2, out, stride, offset ); tmp = f32( -out[ offset ] ); out[ offset ] = out[ offset+stride ]; out[ offset+stride ] = tmp; } } else if ( hx > 0 ) { kernelSincosf( x - TWO_PI, out, stride, offset ); } else { kernelSincosf( x + TWO_PI, out, stride, offset ); } return out; } // Case: x is NaN or infinity if ( ix >= FLOAT32_EXPONENT_MASK ) { out[ offset ] = NaN; out[ offset+stride ] = NaN; return out; } // Argument reduction... n = rempio2f( f32( x ), Y ); // Compute the sine and cosine together: kernelSincosf( Y[ 0 ], out, stride, offset ); switch ( n & 3 ) { case 0: return out; case 1: tmp = out[ offset+stride ]; out[ offset+stride ] = f32( -out[ offset ] ); out[ offset ] = tmp; return out; case 2: out[ offset ] = f32( -out[ offset ] ); out[ offset+stride ] = f32( -out[ offset+stride ] ); return out; default: tmp = f32( -out[ offset+stride ] ); out[ offset+stride ] = out[ offset ]; out[ offset ] = tmp; return out; } } // EXPORTS // module.exports = sincosf; |