Skip to content

Latest commit

 

History

History

is-nonnegative-integer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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 positive infinity, the function will return true, when, in fact, the result is undefined. If x can be infinite, wrap the implementation as follows:

    var PINF = Number.POSITIVE_INFINITY;
    
    function check( x ) {
        return (
            x < PINF &&
            isNonNegativeInteger( x )
        );
    }
    
    var bool = check( PINF );
    // 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