Skip to content

Latest commit

 

History

History

README.md

Ramp Function

Evaluate the ramp function.

The ramp function is defined as

$$R(x) = \begin{cases} x & \textrm{if}\ x \geq 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}$$

or, alternatively, in terms of the max function

$$R(x) = \mathop{\mathrm{max}}( x, 0 )$$

Usage

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

ramp( x )

Evaluates the ramp function.

var v = ramp( 3.14 );
// returns 3.14

v = ramp( -3.14 );
// returns 0.0

v = ramp( NaN );
// returns NaN

Examples

var uniform = require( '@stdlib/random/array/uniform' );
var logEachMap = require( '@stdlib/console/log-each-map' );
var ramp = require( '@stdlib/math/base/special/ramp' );

var opts = {
    'dtype': 'float64'
};
var x = uniform( 101, -10.0, 10.0, opts );

logEachMap( 'R(%0.4f) = %0.4f', x, ramp );

C APIs

Usage

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

stdlib_base_ramp( x )

Evaluates the ramp function.

double y = stdlib_base_ramp( 3.0 );
// returns 3.0

The function accepts the following arguments:

  • x: [in] double input value.
double stdlib_base_ramp( const double x );

Examples

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

int main( void ) {
    const double x[] = { 3.14, -3.14, 0.0, 0.0/0.0 };

    double y;
    int i;
    for ( i = 0; i < 4; i++ ) {
        y = stdlib_base_ramp( x[ i ] );
        printf( "R(%lf) = %lf\n", x[ i ], y );
    }
}

See Also