time-to-botec/squiggle/node_modules/@stdlib/math/base/special/fast/uint32-sqrt
NunoSempere b6addc7f05 feat: add the node modules
Necessary in order to clearly see the squiggle hotwiring.
2022-12-03 12:44:49 +00:00
..
docs feat: add the node modules 2022-12-03 12:44:49 +00:00
lib feat: add the node modules 2022-12-03 12:44:49 +00:00
package.json feat: add the node modules 2022-12-03 12:44:49 +00:00
README.md feat: add the node modules 2022-12-03 12:44:49 +00:00

Square Root

Compute an integer square root.

Usage

var sqrtUint32 = require( '@stdlib/math/base/special/fast/uint32-sqrt' );

sqrtUint32( x )

Returns an approximate square root of an unsigned 32-bit integer x.

var v = sqrtUint32( 9 >>> 0 );
// returns 3

v = sqrtUint32( 2 >>> 0 );
// returns 1

v = sqrtUint32( 3 >>> 0 );
// returns 1

v = sqrtUint32( 0 >>> 0 );
// returns 0

Notes

  • Prefer hardware sqrt over a software implementation.
  • When using a software sqrt, this implementation provides a performance boost when an application requires only approximate computations for integer arguments.
  • For applications requiring high-precision, this implementation is never suitable.

Examples

var sqrtUint32 = require( '@stdlib/math/base/special/fast/uint32-sqrt' );

var v;
var i;

for ( i = 0; i < 101; i++ ) {
    v = sqrtUint32( i >>> 0 );
    console.log( 'sqrt(%d) ≈ %d', i, v );
}