Compute the hypotenuse avoiding overflow and underflow (single-precision).
var hypotf = require( '@stdlib/math/base/special/hypotf' );
Computes the hypotenuse avoiding overflow and underflow (single-precision).
var h = hypotf( -5.0, 12.0 );
// returns 13.0
h = hypotf( -0.0, -0.0 );
// returns +0.0
If either argument is NaN
and the other argument is not +-Infinity
, the function returns NaN
.
var h = hypotf( NaN, 12.0 );
// returns NaN
h = hypotf( 5.0, NaN );
// returns NaN
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var hypotf = require( '@stdlib/math/base/special/hypotf' );
var opts = {
'dtype': 'float32'
};
var x = discreteUniform( 100, -50, 50, opts );
var y = discreteUniform( 100, -50, 50, opts );
logEachMap( 'h(%d,%d) = %0.4f', x, y, hypotf );
#include "stdlib/math/base/special/hypotf.h
Computes the hypotenuse avoiding overflow and underflow (single-precision).
float h = stdlib_base_hypotf( 5.0f, 12.0f );
// returns 13.0f
The function accepts the following arguments:
- x:
[in] float
input value. - y:
[in] float
input value.
float stdlib_base_hypotf( const float x, const float y );
#include "stdlib/math/base/special/hypotf.h"
#include <stdio.h>
int main( void ) {
const float x[] = { 3.0f, 4.0f, 5.0f, 12.0f };
float y;
int i;
for ( i = 0; i < 4; i += 2 ) {
y = stdlib_base_hypotf( x[ i ], x[ i+1 ] );
printf( "hypot(%f, %f) = %f\n", x[ i ], x[ i+1 ], y );
}
}
@stdlib/math/base/special/hypot
: compute the hypotenuse avoiding overflow and underflow.