Skip to content

Latest commit

 

History

History
184 lines (113 loc) · 4.32 KB

File metadata and controls

184 lines (113 loc) · 4.32 KB

tanhf

Compute the hyperbolic tangent of a single-precision floating-point number.

Usage

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

tanhf( x )

Computes the hyperbolic tangent of a single-precision floating-point number.

var v = tanhf( 0.0 );
// returns 0.0

v = tanhf( -0.0 );
// returns -0.0

v = tanhf( 2.0 );
// returns ~0.964

v = tanhf( -2.0 );
// returns ~-0.964

v = tanhf( NaN );
// returns NaN

Examples

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

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

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

C APIs

Usage

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

stdlib_base_tanhf( x )

Computes the hyperbolic tangent of a single-precision floating-point number.

float out = stdlib_base_tanhf( 2.0f );
// returns ~0.964f

The function accepts the following arguments:

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

Examples

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

int main( void ) {
    const float x[] = { -4.0f, -3.11f, -2.22f, -1.33f, -0.44f, 0.44f, 1.33f, 2.22f, 3.11f, 4.0f };

    float v;
    int i;
    for ( i = 0; i < 10; i++ ) {
        v = stdlib_base_tanhf( x[ i ] );
        printf( "tanhf(%f) = %f\n", x[ i ], v );
    }
}

See Also