Logarithm

Compute the base b logarithm of a single-precision floating-point number.

Usage

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

logf( x, b )

Computes the base b logarithm of a single-precision floating-point number.

var v = logf( 100.0, 10.0 );
// returns 2.0

v = logf( 16.0, 2.0 );
// returns 4.0

v = logf( 5.0, 1.0 );
// returns Infinity

For negative x or b, the logarithm is not defined.

var v = logf( -4.0, 1.0 );
// returns NaN

v = logf( 2.0, -4.0 );
// returns NaN

Examples

var randu = require( '@stdlib/random/array/discrete-uniform' );
var logf = require( '@stdlib/math/base/special/logf' );

var opts = {
    'dtype': 'float32'
};

var x = randu( 100, 0, 100, opts );
var b = randu( 100, 0, 5, opts );

var i;
for ( i = 0; i < 100; i++ ) {
    console.log( 'logf( %d, %d ) = %d', x[ i ], b[ i ], logf( x[ i ], b[ i ] ) );
}

C APIs

Usage

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

stdlib_base_logf( x, b )

Computes the base b logarithm of a single-precision floating-point number.

float v = stdlib_base_logf( 100.0f, 10.0f );
// returns 2.0f

The function accepts the following arguments:

  • x: [in] float input value.
  • b: [in] float input value.
float stdlib_base_logf( const float x, const float b );

Examples

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

int main( void ) {
    float out;
    float x;
    float b;
    int i;

    for ( i = 0; i < 100; i++ ) {
        x = ( (float)rand() / (float)RAND_MAX ) * 100.0f;
        b = ( (float)rand() / (float)RAND_MAX ) * 5.0f;
        out = stdlib_base_logf( x, b );
        printf( "logf(%f, %f) = %f\n", x, b, out );
    }
}
Did you find this page helpful?