isIntegerf

Test if a finite single-precision floating-point number is an integer.

Usage

var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' );

isIntegerf( x )

Tests if a finite single-precision floating-point number is an integer.

var bool = isIntegerf( 1.0 );
// returns true

Notes

  • The function assumes a finite number. If provided positive or negative infinity, the function will return true, when, in fact, the result is undefined. If x can be infinite, wrap the implementation as follows:

    function check( x ) {
        return (
            x < Infinity &&
            x > -Infinity &&
            isIntegerf( x )
        );
    }
    
    var bool = check( Infinity );
    // returns false
    
    bool = check( -Infinity );
    // returns false
    

Examples

var isIntegerf = require( '@stdlib/math/base/assert/is-integerf' );

var bool = isIntegerf( -5.0 );
// returns true

bool = isIntegerf( 3.14 );
// returns false

bool = isIntegerf( NaN );
// returns false

C APIs

Usage

#include "stdlib/math/base/assert/is_integerf.h"

stdlib_base_is_integerf( x )

Tests if a finite single-precision floating-point number is an integer.

bool out = stdlib_base_is_integerf( 1.0 );
// returns true

out = stdlib_base_is_integerf( 3.14 );
// returns false

The function accepts the following arguments:

  • x: [in] float input value.
bool stdlib_base_is_integerf( const float x );

Examples

#include "stdlib/math/base/assert/is_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_integerf( x );
        printf( "x = %f, is_integerf(x) = %s\n", x, ( v ) ? "true" : "false" );
    }
}
Did you find this page helpful?