Skip to content

Latest commit

 

History

History
201 lines (124 loc) · 3.87 KB

File metadata and controls

201 lines (124 loc) · 3.87 KB

log1pf

Evaluate the natural logarithm of 1+x as a single‐precision floating-point number.

Usage

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

log1pf( x )

Evaluates the natural logarithm of 1+x as a single‐precision floating-point number.

var v = log1pf( 4.0 );
// returns ~1.609

v = log1pf( -1.0 );
// returns -Infinity

v = log1pf( Infinity );
// returns Infinity

v = log1pf( 0.0 );
// returns 0.0

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

v = log1pf( NaN );
// returns NaN

For x < -1, the function returns NaN, as the natural logarithm is not defined for negative numbers.

var v = log1pf( -2.0 );
// returns NaN

Examples

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

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

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

C APIs

Usage

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

stdlib_base_log1pf( x )

Evaluates the natural logarithm of 1+x as a single‐precision floating-point number.

float out = stdlib_base_log1pf( 4.0f );
// returns ~1.609f

out = stdlib_base_log1pf( -1.0f );
// returns -Infinity

The function accepts the following arguments:

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

Examples

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

int main( void ) {
    float x;
    float v;
    int i;

    for ( i = 0; i < 100; i++ ) {
        x = ( (float)rand() / (float)RAND_MAX ) * 100.0f;
        v = stdlib_base_log1pf( x );
        printf( "log1pf(%f) = %f\n", x, v );
    }
}