isNonNegativeIntegerf
Test if a finite single-precision floating-point number is a nonnegative integer.
Usage
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 false
Notes
The function assumes a finite number. If provided positive
infinity
, 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 && isNonNegativeIntegerf( x ) ); } var bool = check( Infinity ); // returns false
The 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 false
C 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 false
The function accepts the following arguments:
- x:
[in] float
input 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" );
}
}