|
||
---|---|---|
.. | ||
docs | ||
lib | ||
package.json | ||
README.md |
isNonNegativeInteger
Test if a finite double-precision floating-point number is a nonnegative integer.
Usage
var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' );
isNonNegativeInteger( x )
Tests if a finite double-precision floating-point number is a nonnegative integer
.
var bool = isNonNegativeInteger( 1.0 );
// returns true
bool = isNonNegativeInteger( 0.0 );
// returns true
bool = isNonNegativeInteger( -10.0 );
// returns false
Notes
-
The function assumes a finite
number
. If provided positiveinfinity
, the function will returntrue
, when, in fact, the result is undefined. Ifx
can beinfinite
, wrap the implementation as follows:function check( x ) { return ( x < Infinity && isNonNegativeInteger( x ) ); } var bool = check( Infinity ); // returns false
-
The function does not distinguish between positive and negative
zero
.var bool = isNonNegativeInteger( 0.0 ); // returns true bool = isNonNegativeInteger( -0.0 ); // returns true
Examples
var isNonNegativeInteger = require( '@stdlib/math/base/assert/is-nonnegative-integer' );
var bool = isNonNegativeInteger( 5.0 );
// returns true
bool = isNonNegativeInteger( 0.0 );
// returns true
bool = isNonNegativeInteger( -1.0 );
// returns false
bool = isNonNegativeInteger( 3.14 );
// returns false
bool = isNonNegativeInteger( NaN );
// returns false