Modulus Function

Evaluate the Modulus function for single-precision floating-point numbers.

The modulus function is defined as

z equals x

where x is the dividend and y is the divisor.

Usage

var fmodf = require( '@stdlib/math/base/special/fmodf' );

fmodf( x, y )

Evaluates the Modulus function for single-precision floating-point numbers.

var v = fmodf( 8.0, 3.0 );
// returns 2.0

v = fmodf( 9.0, 3.0 );
// returns 0.0

v = fmodf( 8.9, 3.0 );
// returns ~2.9

v = fmodf( NaN, 3.0 );
// returns NaN

v = fmodf( 5.0, NaN );
// returns NaN

v = fmodf( NaN, NaN );
// returns NaN

Examples

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var fmodf = require( '@stdlib/math/base/special/fmodf' );

var x = discreteUniform( 10, 0.0, 100.0 );
var y = discreteUniform( 10, -50.0, 50.0 );
var i;

for ( i = 0; i < 10; i++ ) {
    console.log( '%f%%%f = %f', x[ i ], y[ i ], fmodf( x[ i ], y[ i ] ) );
}

C APIs

Usage

#include "stdlib/math/base/special/fmodf.h"

stdlib_base_fmodf( x, y )

Evaluates the Modulus function for single-precision floating-point numbers.

float out = stdlib_base_fmodf( 8.9f, 3.0f );
// returns 2.9f

out = stdlib_base_fmodf( 4.0f, 2.0f );
// returns 0.0f

The function accepts the following arguments:

  • x: [in] float dividend.
  • y: [in] float divisor.
float stdlib_base_fmodf( const float x, const float y );

Examples

#include "stdlib/math/base/special/fmodf.h"
#include <stdlib.h>
#include <stdio.h>

int main( void ) {
    float x[ 100 ];
    float y[ 100 ];
    float out;
    int i;

    for ( i = 0; i < 100; i++ ) {
        x[ i ] = ( ( (float)rand() / (float)RAND_MAX ) * 10.0f );
        y[ i ] = ( ( (float)rand() / (float)RAND_MAX ) * 10.0f ) - 5.0f;
    }

    for ( i = 0; i < 100; i++ ) {
        out = stdlib_base_fmodf( x[ i ], y[ i ] );
        printf( "fmodf(%f, %f) = %f\n", x[ i ], y[ i ], out );
    }
}
Did you find this page helpful?