Skip to content

Latest commit

 

History

History

README.md

Cosine

Compute the cosine of a single-precision floating-point number (in radians).

Usage

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

cosf( x )

Computes the cosine of a single-precision floating-point number (in radians).

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

v = cosf( 3.141592653589793/4.0 );
// returns ~0.707

v = cosf( -3.141592653589793/6.0 );
// returns ~0.866

v = cosf( NaN );
// returns NaN

Examples

var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var TWO_PI = require( '@stdlib/constants/float32/two-pi' );
var cosf = require( '@stdlib/math/base/special/cosf' );

var opts = {
    'dtype': 'float32'
};
var x = uniform( 100, 0.0, TWO_PI, opts );

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

C APIs

Usage

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

stdlib_base_cosf( x )

Computes the cosine of a single-precision floating-point number (in radians).

float out = stdlib_base_cosf( 0.0f );
// returns 1.0f

out = stdlib_base_cosf( 3.141592653589793f / 4.0f );
// returns ~0.707f

The function accepts the following arguments:

  • x: [in] float input value.
float stdlib_base_cosf( const float x );

Examples

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

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

    float y;
    int i;
    for ( i = 0; i < 5; i++ ) {
        y = stdlib_base_cosf( x[ i ] );
        printf( "cosf(%f) = %f\n", x[ i ], y );
    }
}