@stdlib/math-base-assert-is-oddf
v0.1.1
Published
Test if a finite single-precision floating-point number is an odd number.
Readme
isOddf
Test if a finite single-precision floating-point number is an odd number.
Installation
npm install @stdlib/math-base-assert-is-oddfUsage
var isOddf = require( '@stdlib/math-base-assert-is-oddf' );isOddf( x )
Tests if a finite single-precision floating-point number is an odd number.
var bool = isOddf( 5.0 );
// returns true
bool = isOddf( -2.0 );
// returns false
bool = isOddf( 0.0 );
// returns false
bool = isOddf( 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 && isOddf( 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 isOddf = require( '@stdlib/math-base-assert-is-oddf' );
var opts = {
'dtype': 'float32'
};
var x = discreteUniform( 100, 0, 1000, opts );
function isOddfWrapper( integer ) {
return ( isOddf( integer ) ) ? 'odd' : 'not odd';
}
logEachMap( '%d is %s', x, isOddfWrapper );C APIs
Usage
#include "stdlib/math/base/assert/is_oddf.h"stdlib_base_is_oddf( x )
Tests if a finite single-precision floating-point number is an odd number.
#include <stdbool.h>
bool out = stdlib_base_is_oddf( 1.0f );
// returns true
out = stdlib_base_is_oddf( 4.0f );
// returns falseThe function accepts the following arguments:
- x:
[in] floatinput value.
bool stdlib_base_is_oddf( const float x );Examples
#include "stdlib/math/base/assert/is_oddf.h"
#include <stdio.h>
#include <stdbool.h>
int main( void ) {
const float x[] = { 5.0f, -5.0f, 3.14f, -3.14f, 0.0f, 0.0f / 0.0f };
bool b;
int i;
for ( i = 0; i < 6; i++ ) {
b = stdlib_base_is_oddf( x[ i ] );
printf( "Value: %f. Is Odd? %s.\n", x[ i ], ( b ) ? "True" : "False" );
}
}See Also
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.
