Compute the base
b
logarithm of a single-precision floating-point number.
var logf = require( '@stdlib/math/base/special/logf' );
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
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var logf = require( '@stdlib/math/base/special/logf' );
var opts = {
'dtype': 'float32'
};
var x = discreteUniform( 100, 0, 100, opts );
var b = discreteUniform( 100, 0, 5, opts );
logEachMap( 'logf( %0.4f, %0.4f ) = %0.4f', x, b, logf );
#include "stdlib/math/base/special/logf.h"
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 );
#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 );
}
}