README.md (4160B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Ramp Function 22 23 > Evaluate the [ramp function][ramp-function]. 24 25 <section class="intro"> 26 27 The [ramp function][ramp-function] is defined as 28 29 <!-- <equation class="equation" label="eq:ramp_function" align="center" raw="R(x) = \begin{cases} x & \textrm{if}\ x \geq 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}" alt="Ramp function."> --> 30 31 <div class="equation" align="center" data-raw-text="R(x) = \begin{cases} x & \textrm{if}\ x \geq 0 \\ 0 & \textrm{if}\ x \lt 0\end{cases}" data-equation="eq:ramp_function"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/ramp/docs/img/equation_ramp_function.svg" alt="Ramp function."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 or, alternatively, in terms of the `max` function 39 40 <!-- <equation class="equation" label="eq:ramp_function_alternative_defn" align="center" raw="R(x) = \operatorname{max}( x, 0 )" alt="Ramp function alternative definition."> --> 41 42 <div class="equation" align="center" data-raw-text="R(x) = \operatorname{max}( x, 0 )" data-equation="eq:ramp_function_alternative_defn"> 43 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/ramp/docs/img/equation_ramp_function_alternative_defn.svg" alt="Ramp function alternative definition."> 44 <br> 45 </div> 46 47 <!-- </equation> --> 48 49 </section> 50 51 <!-- /.intro --> 52 53 <section class="usage"> 54 55 ## Usage 56 57 ```javascript 58 var ramp = require( '@stdlib/math/base/special/ramp' ); 59 ``` 60 61 #### ramp( x ) 62 63 Evaluates the [ramp function][ramp-function]. 64 65 ```javascript 66 var v = ramp( 3.14 ); 67 // returns 3.14 68 69 v = ramp( -3.14 ); 70 // returns 0.0 71 72 v = ramp( NaN ); 73 // returns NaN 74 ``` 75 76 </section> 77 78 <!-- /.usage --> 79 80 <section class="examples"> 81 82 ## Examples 83 84 <!-- eslint no-undef: "error" --> 85 86 ```javascript 87 var linspace = require( '@stdlib/array/linspace' ); 88 var ramp = require( '@stdlib/math/base/special/ramp' ); 89 90 var x = linspace( -10.0, 10.0, 101 ); 91 var i; 92 93 for ( i = 0; i < x.length; i++ ) { 94 console.log( 'R(%d) = %d', x[ i ], ramp( x[ i ] ) ); 95 } 96 ``` 97 98 </section> 99 100 <!-- /.examples --> 101 102 <!-- C interface documentation. --> 103 104 * * * 105 106 <section class="c"> 107 108 ## C APIs 109 110 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 111 112 <section class="intro"> 113 114 </section> 115 116 <!-- /.intro --> 117 118 <!-- C usage documentation. --> 119 120 <section class="usage"> 121 122 ### Usage 123 124 ```c 125 #include "stdlib/math/base/special/ramp.h" 126 ``` 127 128 #### stdlib_base_ramp( x ) 129 130 Evaluates the ramp function. 131 132 ```c 133 double y = stdlib_base_ramp( 3.0 ); 134 // returns 3.0 135 ``` 136 137 The function accepts the following arguments: 138 139 - **x**: `[in] double` input value. 140 141 ```c 142 double stdlib_base_ramp( const double x ); 143 ``` 144 145 </section> 146 147 <!-- /.usage --> 148 149 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 150 151 <section class="notes"> 152 153 </section> 154 155 <!-- /.notes --> 156 157 <!-- C API usage examples. --> 158 159 <section class="examples"> 160 161 ### Examples 162 163 ```c 164 #include "stdlib/math/base/special/ramp.h" 165 #include <stdio.h> 166 167 int main() { 168 double x[] = { 3.14, -3.14, 0.0, 0.0/0.0 }; 169 170 double y; 171 int i; 172 for ( i = 0; i < 4; i++ ) { 173 y = stdlib_base_ramp( x[ i ] ); 174 printf( "R(%lf) = %lf\n", x[ i ], y ); 175 } 176 } 177 ``` 178 179 </section> 180 181 <!-- /.examples --> 182 183 </section> 184 185 <!-- /.c --> 186 187 <section class="links"> 188 189 [ramp-function]: https://en.wikipedia.org/wiki/Ramp_function 190 191 </section> 192 193 <!-- /.links -->