Secant

Evaluate the secant of a number.

Usage

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

sec( x )

Evaluates the secant of x (in radians).

var v = sec( 0.0 );
// returns 1.0

v = sec( 3.141592653589793/2.0 );
// returns 16331239353195370.0

v = sec( -3.141592653589793/3.0 );
// returns ~1.9999999999999996

v = sec( 3.141592653589793/3.0 );
// returns ~1.9999999999999996

v = sec( NaN );
// returns NaN

Examples

var linspace = require( '@stdlib/array/base/linspace' );
var PI = require( '@stdlib/constants/float64/pi' );
var sec = require( '@stdlib/math/base/special/sec' );

var x = linspace( -PI/2.0, PI/2.0, 100 );

var i;
for ( i = 0; i < x.length; i++ ) {
    console.log( sec( x[ i ] ) );
}

C APIs

Usage

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

stdlib_base_sec( x )

Evaluates the secant of x (in radians).

double out = stdlib_base_sec( 0.0 );
// returns 1.0

out = stdlib_base_cos( 3.141592653589793 / 2.0 );
// returns 6.123233995736766e-17

The function accepts the following arguments:

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

Examples

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

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

    double y;
    int i;
    for ( i = 0; i < 4; i++ ) {
        y = stdlib_base_sec( x[ i ] );
        printf( "sec(%lf) = %lf\n", x[ i ], y );
    }
}
Did you find this page helpful?