Compute the principal square root of a single-precision floating-point number.
The principal square root is defined as
var sqrtf = require( '@stdlib/math/base/special/sqrtf' );
Computes the principal square root of a single-precision floating-point number.
var v = sqrtf( 4.0 );
// returns 2.0
v = sqrtf( 9.0 );
// returns 3.0
v = sqrtf( 0.0 );
// returns 0.0
v = sqrtf( NaN );
// returns NaN
For negative numbers, the principal square root is not defined.
var v = sqrtf( -4.0 );
// returns NaN
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var sqrtf = require( '@stdlib/math/base/special/sqrtf' );
var opts = {
'dtype': 'float32'
};
var x = discreteUniform( 100, 0, 100, opts );
logEachMap( 'sqrt(%d) = %0.4f', x, sqrtf );
#include "stdlib/math/base/special/sqrtf.h"
Computes the principal square root of a single-precision floating-point number.
float y = stdlib_base_sqrtf( 9.0f );
// returns 3.0f
The function accepts the following arguments:
- x:
[in] float
input value.
float stdlib_base_sqrtf( const float x );
#include "stdlib/math/base/special/sqrtf.h"
#include <stdio.h>
int main( void ) {
const float x[] = { 3.14f, 9.0f, 0.0f, 0.0f/0.0f };
float y;
int i;
for ( i = 0; i < 4; i++ ) {
y = stdlib_base_sqrtf( x[ i ] );
printf( "sqrt(%f) = %f\n", x[ i ], y );
}
}
@stdlib/math/base/special/cbrtf
: compute the cube root of a single-precision floating-point number.@stdlib/math/base/special/rsqrtf
: compute the reciprocal square root of a single-precision floating-point number.@stdlib/math/base/special/sqrt
: compute the principal square root of a double-precision floating-point number.