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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 24005x 24005x 24005x 24005x 24005x 24005x 24005x 24005x 24005x 24005x 10x 10x 4x 4x 6x 6x 23995x 24005x 32x 32x 16x 8x 8x 8x 8x 32x 8x 8x 8x 8x 23963x 24005x 32x 32x 16x 8x 8x 8x 8x 32x 8x 8x 8x 8x 23931x 24005x 3x 3x 23928x 23928x 23928x 24005x 5802x 24005x 6042x 24005x 6042x 24005x 6042x 24005x 24005x 1x 1x 1x 1x 1x | /** * @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, license, and long comment were part of the original implementation available as part of [FreeBSD]{@link https://svnweb.freebsd.org/base/release/12.2.0/lib/msun/src/s_sinf.c}. The implementation follows the original, but has been modified for JavaScript. * * ```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 kernelCosf = require( '@stdlib/math/base/special/kernel-cosf' ); var kernelSinf = require( '@stdlib/math/base/special/kernel-sinf' ); var rempio2f = require( '@stdlib/math/base/special/rempio2f' ); var toWordf = require( '@stdlib/number/float32/base/to-word' ); 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' ); // 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 // /** * Computes the sine of a single-precision floating-point number (in radians). * * ## 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 | * * @param {number} x - input value (in radians) * @returns {number} sine * * @example * var v = sinf( 0.0 ); * // returns ~0.0 * * @example * var v = sinf( 3.141592653589793/2.0 ); * // returns ~1.0 * * @example * var v = sinf( -3.141592653589793/6.0 ); * // returns ~-0.5 * * @example * var v = sinf( NaN ); * // returns NaN */ function sinf( x ) { 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 ) { return f32( x ); } return kernelSinf( x ); } // Case: |x| ~<= 5π/4 if ( ix <= FIVE_PIO4_WORD ) { // Case: |x| ~<= 3π/4 if ( ix <= THREE_PIO4_WORD ) { if ( hx > 0 ) { return f32( kernelCosf( x - PIO2 ) ); } return f32( -kernelCosf( x + PIO2 ) ); } if ( hx > 0 ) { return f32( kernelSinf( PI - x ) ); } return f32( -kernelSinf( PI + x ) ); } // Case: |x| ~<= 9π/4 if ( ix <= NINE_PIO4_WORD ) { // Case: |x| ~<= 7π/4 if ( ix <= SEVEN_PIO4_WORD ) { if ( hx > 0 ) { return f32( -kernelCosf( x - THREE_PIO2 ) ); } return f32( kernelCosf( x + THREE_PIO2 ) ); } if ( hx > 0 ) { return f32( kernelSinf( x - TWO_PI ) ); } return f32( kernelSinf( x + TWO_PI ) ); } // Case: x is NaN or infinity if ( ix >= FLOAT32_EXPONENT_MASK ) { return NaN; } // Argument reduction... n = rempio2f( f32( x ), Y ); switch ( n & 3 ) { case 0: return f32( kernelSinf( Y[ 0 ] ) ); case 1: return f32( kernelCosf( Y[ 0 ] ) ); case 2: return f32( -kernelSinf( Y[ 0 ] ) ); default: return f32( -kernelCosf( Y[ 0 ] ) ); } } // EXPORTS // module.exports = sinf; |