@stdlib/math-base-assert-is-nonnegative-integerf
v0.1.1
Published
Test if a finite single-precision floating-point number is a nonnegative integer.
Downloads
183
Readme
isNonNegativeIntegerf
Test if a finite single-precision floating-point number is a nonnegative integer.
Installation
npm install @stdlib/math-base-assert-is-nonnegative-integerfUsage
var isNonNegativeIntegerf = require( '@stdlib/math-base-assert-is-nonnegative-integerf' );isNonNegativeIntegerf( x )
Tests if a finite single-precision floating-point number is a nonnegative integer.
var bool = isNonNegativeIntegerf( 1.0 );
// returns true
bool = isNonNegativeIntegerf( 0.0 );
// returns true
bool = isNonNegativeIntegerf( -10.0 );
// returns falseNotes
The function assumes a finite number. If provided positive
infinity, the function will returntrue, when, in fact, the result is undefined. Ifxcan beinfinite, wrap the implementation as follows:function check( x ) { return ( x < Infinity && isNonNegativeIntegerf( x ) ); } var bool = check( Infinity ); // returns falseThe function does not distinguish between positive and negative
zero.var bool = isNonNegativeIntegerf( 0.0 ); // returns true bool = isNonNegativeIntegerf( -0.0 ); // returns true
Examples
var isNonNegativeIntegerf = require( '@stdlib/math-base-assert-is-nonnegative-integerf' );
var bool = isNonNegativeIntegerf( 5.0 );
// returns true
bool = isNonNegativeIntegerf( 0.0 );
// returns true
bool = isNonNegativeIntegerf( -1.0 );
// returns false
bool = isNonNegativeIntegerf( 3.14 );
// returns false
bool = isNonNegativeIntegerf( NaN );
// returns falseC APIs
Usage
#include "stdlib/math/base/assert/is_nonnegative_integerf.h"stdlib_base_is_nonnegative_integerf( x )
Tests if a finite single-precision floating-point number is a nonnegative integer.
#include <stdbool.h>
bool out = stdlib_base_is_nonnegative_integerf( 1.0f );
// returns true
out = stdlib_base_is_nonnegative_integerf( -10.0f );
// returns falseThe function accepts the following arguments:
- x:
[in] floatinput value.
bool stdlib_base_is_nonnegative_integerf( const float x );Examples
#include "stdlib/math/base/assert/is_nonnegative_integerf.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main( void ) {
float x;
bool v;
int i;
for ( i = 0; i < 100; i++ ) {
x = ( ( (float)rand() / (float)RAND_MAX ) * 100.0f ) - 50.0f;
v = stdlib_base_is_nonnegative_integerf( x );
printf( "x = %f, is_nonnegative_integerf(x) = %s\n", x, ( v ) ? "true" : "false" );
}
}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.
