@stdlib/math-base-special-fast-hypotf
v0.1.1
Published
Compute the hypotenuse of a single-precision floating-point number.
Readme
hypotf
Compute the hypotenuse of two single-precision floating-point numbers.
Installation
npm install @stdlib/math-base-special-fast-hypotfUsage
var hypotf = require( '@stdlib/math-base-special-fast-hypotf' );hypotf( x, y )
Computes the hypotenuse of two single-precision floating-point numbers.
var h = hypotf( -5.0, 12.0 );
// returns 13.0Notes
For a sufficiently large
xand/ory, computing the hypotenuse will overflow.var h = hypotf( 1.0e38, 1.0e38 ); // returns InfinitySimilarly, for sufficiently small
xand/ory, computing the hypotenuse will underflow.var h = hypotf( 1.0e-45, 1.0e-45 ); // returns 0.0
Examples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var hypotf = require( '@stdlib/math-base-special-fast-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 );C APIs
Usage
#include "stdlib/math/base/special/fast/hypotf.h"stdlib_base_fast_hypotf( x, y )
Computes the hypotenuse of two single-precision floating-point numbers.
float h = stdlib_base_fast_hypotf( 5.0f, 12.0f );
// returns 13.0fThe function accepts the following arguments:
- x:
[in] floatinput value. - y:
[in] floatinput value.
float stdlib_base_fast_hypotf( const float x, const float y );Examples
#include "stdlib/math/base/special/fast/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_fast_hypotf( x[ i ], x[ i+1 ] );
printf( "hypot(%f, %f) = %f\n", x[ i ], x[ i+1 ], y );
}
}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.
