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 randu = require( '@stdlib/random/base/randu' );
var roundf = require( '@stdlib/math/base/special/roundf' );
var logf = require( '@stdlib/math/base/special/logf' );
var b;
var x;
var i;
for ( i = 0; i < 100; i++ ) {
x = roundf( randu() * 100.0 );
b = roundf( randu() * 5.0 );
console.log( 'logf( %d, %d ) = %d', x, b, logf( x, b ) );
}
#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 );
}
}