@stdlib/math-base-special-logf
v0.1.1
Published
Compute the base `b` logarithm of a single-precision floating-point number.
Readme
Logarithm
Compute the base
blogarithm of a single-precision floating-point number.
Installation
npm install @stdlib/math-base-special-logfUsage
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 InfinityFor 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 NaNExamples
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( %d, %d ) = %0.4f', x, b, logf );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.0fThe function accepts the following arguments:
- x:
[in] floatinput value. - b:
[in] floatinput 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 );
}
}Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
