Skip to content

Latest commit

 

History

History
214 lines (129 loc) · 4.53 KB

File metadata and controls

214 lines (129 loc) · 4.53 KB

sinc

Compute the cardinal sine of a number.

The normalized cardinal sine function is defined as

$$\mathop{\mathrm{sinc}}(x) := \begin{cases} \frac {\sin(\pi x)}{\pi x} & \textrm{if}\ x \neq 0 \\ 1 & \textrm{if}\ x = 0 \end{cases}$$

for any real number x.

Usage

var sinc = require( '@stdlib/math/base/special/sinc' );

sinc( x )

Computes the normalized cardinal sine of a number.

var v = sinc( 0.5 );
// returns ~0.637

v = sinc( -1.2 );
// returns ~-0.156

v = sinc( 0.0 );
// returns 1.0

v = sinc( NaN );
// returns NaN

Examples

var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var sinc = require( '@stdlib/math/base/special/sinc' );

var opts = {
    'dtype': 'float64'
};
var x = uniform( 100, -5.0, 5.0, opts );

logEachMap( 'sinc( %0.4f ) = %0.4f', x, sinc );

C APIs

Usage

#include "stdlib/math/base/special/sinc.h"

stdlib_base_sinc( x )

Computes the normalized cardinal sine of a number.

double y = stdlib_base_sinc( 0.5 );
// returns ~0.637

The function accepts the following arguments:

  • x: [in] double input value.
double stdlib_base_sinc( const double x );

Examples

#include "stdlib/math/base/special/sinc.h"
#include <stdio.h>

int main( void ) {
    const double x[] = { 0.0, 0.523, 0.785, 1.047, 3.14 };

    double y;
    int i;
    for ( i = 0; i < 5; i++ ) {
        y = stdlib_base_sinc( x[ i ] );
        printf( "sinc(%lf) = %lf\n", x[ i ], y );
    }
}

See Also