Compute the absolute value of a single-precision floating-point number.
The absolute value is defined as
var absf = require( '@stdlib/math/base/special/absf' );Computes the absolute value of a single-precision floating-point number.
var v = absf( -1.0 );
// returns 1.0
v = absf( 2.0 );
// returns 2.0
v = absf( 0.0 );
// returns 0.0
v = absf( -0.0 );
// returns 0.0
v = absf( NaN );
// returns NaNvar discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var absf = require( '@stdlib/math/base/special/absf' );
var x = discreteUniform( 100, -50, 50, {
'dtype': 'float32'
});
logEachMap( 'absf(%d) = %d', x, absf );#include "stdlib/math/base/special/absf.h"Computes the absolute value of a single-precision floating-point number.
float y = stdlib_base_absf( -5.0f );
// returns 5.0fThe function accepts the following arguments:
- x:
[in] floatinput value.
float stdlib_base_absf( const float x );#include "stdlib/math/base/special/absf.h"
#include <stdio.h>
int main( void ) {
const float x[] = { 3.14f, -3.14f, 0.0f, 0.0f/0.0f };
float y;
int i;
for ( i = 0; i < 4; i++ ) {
y = stdlib_base_absf( x[ i ] );
printf( "|%f| = %f\n", x[ i ], y );
}
}@stdlib/math/base/special/abs: compute the absolute value of a double-precision floating-point number.@stdlib/math/base/special/abs2f: compute the squared absolute value of a single-precision floating-point number.@stdlib/math/base/special/labs: compute an absolute value of a signed 32-bit integer.