@stdlib/math-base-assert-is-evenf
v0.1.1
Published
Test if a finite single-precision floating-point number is an even number.
Downloads
350
Readme
isEvenf
Test if a finite single-precision floating-point number is an even number.
Installation
npm install @stdlib/math-base-assert-is-evenfUsage
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 falseNotes
The function assumes a finite
number. If provided positive or negativeinfinity, the function will returntrue, when, in fact, the result is undefined. Ifxcan 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 discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var isEvenf = require( '@stdlib/math-base-assert-is-evenf' );
var opts = {
'dtype': 'float32'
};
var x = discreteUniform( 100, 0, 100, opts );
function isEvenfWrapper( integer ) {
return ( isEvenf( integer ) ) ? 'even' : 'not even';
}
logEachMap( '%d is %s', x, isEvenfWrapper );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 trueThe function accepts the following arguments:
- x:
[in] floatinput 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" );
}
}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.
