|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2026 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# sincospif |
| 22 | + |
| 23 | +> Simultaneously compute the [sinef][@stdlib/math/base/special/sinf] and [cosinef][@stdlib/math/base/special/cosf] of a single-precision floating-point number times [π][@stdlib/constants/float32/pi]. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var sincospif = require( '@stdlib/math/base/special/sincospif' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### sincospif( x ) |
| 34 | + |
| 35 | +Simultaneously computes the [sinef][@stdlib/math/base/special/sinf] and [cosinef][@stdlib/math/base/special/cosf] of a single-precision floating-point number times [π][@stdlib/constants/float32/pi] more accurately than `sincos(pi*x)` when operating on single-precision floating-point values, especially for large `x`. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var v = sincospif( 0.0 ); |
| 39 | +// returns <Float32Array>[ 0.0, 1.0 ] |
| 40 | + |
| 41 | +v = sincospif( 0.5 ); |
| 42 | +// returns <Float32Array>[ 1.0, 0.0 ] |
| 43 | + |
| 44 | +v = sincospif( 0.1 ); |
| 45 | +// returns <Float32Array>[ ~0.309, ~0.951 ] |
| 46 | + |
| 47 | +v = sincospif( NaN ); |
| 48 | +// returns <Float32Array>[ NaN, NaN ] |
| 49 | +``` |
| 50 | + |
| 51 | +#### sincospif( x, out, stride, offset ) |
| 52 | + |
| 53 | +Simultaneously computes the [sinef][@stdlib/math/base/special/sinf] and [cosinef][@stdlib/math/base/special/cosf] of a single-precision floating-point number times [π][@stdlib/constants/float32/pi] more accurately than `sincos(pi*x)`, especially for large `x`, and assigns results to a provided output array. |
| 54 | + |
| 55 | +<!-- eslint-disable stdlib/doctest --> |
| 56 | + |
| 57 | +```javascript |
| 58 | +var Float32Array = require( '@stdlib/array/float32' ); |
| 59 | + |
| 60 | +var out = new Float32Array( 2 ); |
| 61 | + |
| 62 | +var v = sincospif.assign( 0.0, out, 1, 0 ); |
| 63 | +// returns <Float32Array>[ 0.0, 1.0 ] |
| 64 | + |
| 65 | +var bool = ( v === out ); |
| 66 | +// returns true |
| 67 | +``` |
| 68 | + |
| 69 | +</section> |
| 70 | + |
| 71 | +<!-- /.usage --> |
| 72 | + |
| 73 | +<section class="examples"> |
| 74 | + |
| 75 | +## Examples |
| 76 | + |
| 77 | +<!-- eslint no-undef: "error" --> |
| 78 | + |
| 79 | +```javascript |
| 80 | +var linspace = require( '@stdlib/array/base/linspace' ); |
| 81 | +var sincospif = require( '@stdlib/math/base/special/sincospif' ); |
| 82 | + |
| 83 | +var x = linspace( 0.0, 2.0, 101 ); |
| 84 | + |
| 85 | +var i; |
| 86 | +for ( i = 0; i < x.length; i++ ) { |
| 87 | + console.log( sincospif( x[ i ] ) ); |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +</section> |
| 92 | + |
| 93 | +<!-- /.examples --> |
| 94 | + |
| 95 | +<!-- C interface documentation. --> |
| 96 | + |
| 97 | +* * * |
| 98 | + |
| 99 | +<section class="c"> |
| 100 | + |
| 101 | +## C APIs |
| 102 | + |
| 103 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 104 | + |
| 105 | +<section class="intro"> |
| 106 | + |
| 107 | +</section> |
| 108 | + |
| 109 | +<!-- /.intro --> |
| 110 | + |
| 111 | +<!-- C usage documentation. --> |
| 112 | + |
| 113 | +<section class="usage"> |
| 114 | + |
| 115 | +### Usage |
| 116 | + |
| 117 | +```c |
| 118 | +#include "stdlib/math/base/special/sincospif.h" |
| 119 | +``` |
| 120 | + |
| 121 | +#### stdlib_base_sincospif( x, &sine, &cosine ) |
| 122 | + |
| 123 | +Simultaneously computes the [sinef][@stdlib/math/base/special/sinf] and [cosinef][@stdlib/math/base/special/cosf] of a single-precision floating-point number times [π][@stdlib/constants/float32/pi] more accurately than `sincos(pi*x)`, especially for large `x`. |
| 124 | + |
| 125 | +```c |
| 126 | +float cosine; |
| 127 | +float sine; |
| 128 | + |
| 129 | +stdlib_base_sincospif( 4.0, &sine, &cosine ); |
| 130 | +``` |
| 131 | +
|
| 132 | +The function accepts the following arguments: |
| 133 | +
|
| 134 | +- **x**: `[in] float` input value. |
| 135 | +- **sine**: `[out] float*` destination for the sine. |
| 136 | +- **cosine**: `[out] float*` destination for the cosine. |
| 137 | +
|
| 138 | +```c |
| 139 | +void stdlib_base_sincospif( const float x, float *sine, float *cosine ); |
| 140 | +``` |
| 141 | + |
| 142 | +</section> |
| 143 | + |
| 144 | +<!-- /.usage --> |
| 145 | + |
| 146 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 147 | + |
| 148 | +<section class="notes"> |
| 149 | + |
| 150 | +</section> |
| 151 | + |
| 152 | +<!-- /.notes --> |
| 153 | + |
| 154 | +<!-- C API usage examples. --> |
| 155 | + |
| 156 | +<section class="examples"> |
| 157 | + |
| 158 | +### Examples |
| 159 | + |
| 160 | +```c |
| 161 | +#include "stdlib/math/base/special/sincospif.h" |
| 162 | +#include <stdio.h> |
| 163 | + |
| 164 | +int main( void ) { |
| 165 | + const float x[] = { 0.0f, 0.5f, 1.0f, 2.0f }; |
| 166 | + |
| 167 | + float cosine; |
| 168 | + float sine; |
| 169 | + int i; |
| 170 | + for ( i = 0; i < 4; i++ ) { |
| 171 | + stdlib_base_sincospif( x[ i ], &sine, &cosine ); |
| 172 | + printf( "x: %f => sine: %f, cosine: %f\n", x[ i ], sine, cosine ); |
| 173 | + } |
| 174 | +} |
| 175 | +``` |
| 176 | +
|
| 177 | +</section> |
| 178 | +
|
| 179 | +<!-- /.examples --> |
| 180 | +
|
| 181 | +</section> |
| 182 | +
|
| 183 | +<!-- /.c --> |
| 184 | +
|
| 185 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 186 | +
|
| 187 | +<section class="related"> |
| 188 | +
|
| 189 | +* * * |
| 190 | +
|
| 191 | +## See Also |
| 192 | +
|
| 193 | +- <span class="package-name">[`@stdlib/math/base/special/cospif`][@stdlib/math/base/special/cospif]</span><span class="delimiter">: </span><span class="description">compute cos(πx).</span> |
| 194 | +- <span class="package-name">[`@stdlib/math/base/special/sincosf`][@stdlib/math/base/special/sincosf]</span><span class="delimiter">: </span><span class="description">simultaneously compute the sine and cosine of an angle measured in radians.</span> |
| 195 | +- <span class="package-name">[`@stdlib/math/base/special/sinpif`][@stdlib/math/base/special/sinpif]</span><span class="delimiter">: </span><span class="description">compute sin(πx).</span> |
| 196 | +
|
| 197 | +</section> |
| 198 | +
|
| 199 | +<!-- /.related --> |
| 200 | +
|
| 201 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 202 | +
|
| 203 | +<section class="links"> |
| 204 | +
|
| 205 | +[@stdlib/math/base/special/sinf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sinf |
| 206 | +
|
| 207 | +[@stdlib/math/base/special/cosf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cosf |
| 208 | +
|
| 209 | +[@stdlib/constants/float32/pi]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float32/pi |
| 210 | +
|
| 211 | +<!-- <related-links> --> |
| 212 | +
|
| 213 | +[@stdlib/math/base/special/cospif]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/cospif |
| 214 | +
|
| 215 | +[@stdlib/math/base/special/sincosf]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sincosf |
| 216 | +
|
| 217 | +[@stdlib/math/base/special/sinpif]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/sinpif |
| 218 | +
|
| 219 | +<!-- </related-links> --> |
| 220 | +
|
| 221 | +</section> |
| 222 | +
|
| 223 | +<!-- /.links --> |
0 commit comments