Skip to content

Files

Latest commit

 

History

History

is-nonnegative-integer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Feb 2, 2018
Apr 12, 2019
Feb 2, 2018
Feb 2, 2018
Feb 2, 2018
Feb 2, 2018
Apr 12, 2019

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:

    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