isOddf
Test if a finite single-precision floating-point number is an odd number.
Usage
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 false
Notes
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 randu = require( '@stdlib/random/array/discrete-uniform' );
var isOddf = require( '@stdlib/math/base/assert/is-oddf' );
var x = randu( 100, 0, 100 );
var i;
for ( i = 0; i < 100; i++ ) {
console.log( '%d is %s', x[ i ], ( isOddf( x[ i ] ) ) ? 'odd' : 'not odd' );
}
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 false
The 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" );
}
}