|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +# sincf |
| 22 | + |
| 23 | +> Compute the [cardinal sine][sinc] of a single-precision floating-point number (in radians). |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +The normalized [cardinal sine][sinc] function is defined as |
| 28 | + |
| 29 | +<!-- <equation class="equation" label="eq:sinc_function" align="center" raw="\operatorname{sinc}(x) := \begin{cases} \frac {\sin(\pi x)}{\pi x} & \textrm{if}\ x \neq 0 \\ 1 & \textrm{if}\ x = 0 \end{cases}" alt="Sinc function"> --> |
| 30 | + |
| 31 | +```math |
| 32 | +\mathop{\mathrm{sinc}}(x) := \begin{cases} \frac {\sin(\pi x)}{\pi x} & \textrm{if}\ x \neq 0 \\ 1 & \textrm{if}\ x = 0 \end{cases} |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- </equation> --> |
| 36 | + |
| 37 | +for any real number `x`. |
| 38 | + |
| 39 | +</section> |
| 40 | + |
| 41 | +<!-- /.intro --> |
| 42 | + |
| 43 | +<section class="usage"> |
| 44 | + |
| 45 | +## Usage |
| 46 | + |
| 47 | +```javascript |
| 48 | +var sincf = require( '@stdlib/math/base/special/sincf' ); |
| 49 | +``` |
| 50 | + |
| 51 | +#### sincf( x ) |
| 52 | + |
| 53 | +Computes the normalized [cardinal sine][sinc] of a single-precision floating-point number (in radians). |
| 54 | + |
| 55 | +```javascript |
| 56 | +var v = sincf( 0.5 ); |
| 57 | +// returns ~0.637 |
| 58 | + |
| 59 | +v = sincf( -1.2 ); |
| 60 | +// returns ~-0.156 |
| 61 | + |
| 62 | +v = sincf( 0.0 ); |
| 63 | +// returns 1.0 |
| 64 | + |
| 65 | +v = sincf( NaN ); |
| 66 | +// returns NaN |
| 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 uniform = require( '@stdlib/random/array/uniform' ); |
| 81 | +var logEachMap = require( '@stdlib/console/log-each-map' ); |
| 82 | +var sincf = require( '@stdlib/math/base/special/sincf' ); |
| 83 | + |
| 84 | +var opts = { |
| 85 | + 'dtype': 'float32' |
| 86 | +}; |
| 87 | +var x = uniform( 100, -5.0, 5.0, opts ); |
| 88 | + |
| 89 | +logEachMap( 'sincf( %0.4f ) = %0.4f', x, sincf ); |
| 90 | +``` |
| 91 | + |
| 92 | +</section> |
| 93 | + |
| 94 | +<!-- /.examples --> |
| 95 | + |
| 96 | +<!-- C interface documentation. --> |
| 97 | + |
| 98 | +* * * |
| 99 | + |
| 100 | +<section class="c"> |
| 101 | + |
| 102 | +## C APIs |
| 103 | + |
| 104 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 105 | + |
| 106 | +<section class="intro"> |
| 107 | + |
| 108 | +</section> |
| 109 | + |
| 110 | +<!-- /.intro --> |
| 111 | + |
| 112 | +<!-- C usage documentation. --> |
| 113 | + |
| 114 | +<section class="usage"> |
| 115 | + |
| 116 | +### Usage |
| 117 | + |
| 118 | +```c |
| 119 | +#include "stdlib/math/base/special/sincf.h" |
| 120 | +``` |
| 121 | + |
| 122 | +#### stdlib_base_sincf( x ) |
| 123 | + |
| 124 | +Computes the normalized [cardinal sine][sinc] of a single-precision floating-point number (in radians). |
| 125 | + |
| 126 | +```c |
| 127 | +float y = stdlib_base_sincf( 0.5f ); |
| 128 | +// returns ~0.637f |
| 129 | +``` |
| 130 | + |
| 131 | +The function accepts the following arguments: |
| 132 | + |
| 133 | +- **x**: `[in] float` input value. |
| 134 | + |
| 135 | +```c |
| 136 | +float stdlib_base_sincf( const float x ); |
| 137 | +``` |
| 138 | +
|
| 139 | +</section> |
| 140 | +
|
| 141 | +<!-- /.usage --> |
| 142 | +
|
| 143 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 144 | +
|
| 145 | +<section class="notes"> |
| 146 | +
|
| 147 | +</section> |
| 148 | +
|
| 149 | +<!-- /.notes --> |
| 150 | +
|
| 151 | +<!-- C API usage examples. --> |
| 152 | +
|
| 153 | +<section class="examples"> |
| 154 | +
|
| 155 | +### Examples |
| 156 | +
|
| 157 | +```c |
| 158 | +#include "stdlib/math/base/special/sincf.h" |
| 159 | +#include <stdio.h> |
| 160 | +
|
| 161 | +int main( void ) { |
| 162 | + const float x[] = { 0.0f, 0.523f, 0.785f, 1.047f, 3.14f }; |
| 163 | +
|
| 164 | + float y; |
| 165 | + int i; |
| 166 | + for ( i = 0; i < 5; i++ ) { |
| 167 | + y = stdlib_base_sincf( x[ i ] ); |
| 168 | + printf( "sincf(%f) = %f\n", x[ i ], y ); |
| 169 | + } |
| 170 | +} |
| 171 | +``` |
| 172 | + |
| 173 | +</section> |
| 174 | + |
| 175 | +<!-- /.examples --> |
| 176 | + |
| 177 | +</section> |
| 178 | + |
| 179 | +<!-- /.c --> |
| 180 | + |
| 181 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 182 | + |
| 183 | +<section class="related"> |
| 184 | + |
| 185 | +</section> |
| 186 | + |
| 187 | +<!-- /.related --> |
| 188 | + |
| 189 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 190 | + |
| 191 | +<section class="links"> |
| 192 | + |
| 193 | +[sinc]: https://en.wikipedia.org/wiki/Sinc_function |
| 194 | + |
| 195 | +<!-- <related-links> --> |
| 196 | + |
| 197 | +<!-- </related-links> --> |
| 198 | + |
| 199 | +</section> |
| 200 | + |
| 201 | +<!-- /.links --> |
0 commit comments