@stdlib/math-base-special-fmodf
v0.1.1
Published
Evaluate the modulus function for single-precision floating-point numbers.
Readme
Modulus Function
Evaluate the Modulus function for single-precision floating-point numbers.
The modulus function is defined as
where x is the dividend and y is the divisor.
Installation
npm install @stdlib/math-base-special-fmodfUsage
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 NaNExamples
var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var logEachMap = require( '@stdlib/console-log-each-map' );
var fmodf = require( '@stdlib/math-base-special-fmodf' );
var opts = {
'dtype': 'float32'
};
var x = discreteUniform( 100, 0, 100, opts );
var y = discreteUniform( 100, -50, 50, opts );
logEachMap( '%d%%%d = %d', x, y, fmodf );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.0fThe function accepts the following arguments:
- x:
[in] floatdividend. - y:
[in] floatdivisor.
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 );
}
}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
Copyright
Copyright © 2016-2026. The Stdlib Authors.
