isEvenf
Test if a finite single-precision floating-point number is an even number.
Usage
var isEvenf = require( '@stdlib/math/base/assert/is-evenf' );
isEvenf( x )
Tests if a finite single-precision floating-point number is an even number.
var bool = isEvenf( 5.0 );
// returns false
bool = isEvenf( -2.0 );
// returns true
bool = isEvenf( 0.0 );
// returns true
bool = isEvenf( NaN );
// returns false
Notes
The function assumes a finite
number
. If provided positive or negativeinfinity
, 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 && x > -Infinity && isEvenf( x ) ); } var bool = check( Infinity ); // returns false bool = check( -Infinity ); // returns false
Examples
var randu = require( '@stdlib/random/array/discrete-uniform' );
var isEvenf = require( '@stdlib/math/base/assert/is-evenf' );
var x = randu( 100, 0, 100 );
var i;
for ( i = 0; i < 100; i++ ) {
console.log( '%d is %s', x[ i ], ( isEvenf( x[ i ] ) ) ? 'even' : 'not even' );
}
C APIs
Usage
#include "stdlib/math/base/assert/is_evenf.h"
stdlib_base_is_evenf( x )
Tests if a finite single-precision floating-point number is an even number.
#include <stdbool.h>
bool out = stdlib_base_is_evenf( 1.0f );
// returns false
out = stdlib_base_is_evenf( 4.0f );
// returns true
The function accepts the following arguments:
- x:
[in] float
input value.
bool stdlib_base_is_evenf( const float x );
Examples
#include "stdlib/math/base/assert/is_evenf.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 );
v = stdlib_base_is_evenf( x );
printf( "x = %f, is_evenf(x) = %s\n", x, ( v ) ? "even" : "not even" );
}
}