README.md (3760B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2020 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 # Identity Function 22 23 > Evaluate the [identity function][identity-function] of a double-precision floating-point number. 24 25 <section class="intro"> 26 27 The [identity-function][identity-function] is defined as 28 29 <!-- <equation class="equation" label="eq:identity_function" align="center" raw="f(x) = x" alt="Identity function"> --> 30 31 <div class="equation" align="center" data-raw-text="f(x) = x" data-equation="eq:identity_function"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@ad7afa5d7ec1b1596f8a4828153d8c2e87a90161/lib/node_modules/@stdlib/math/base/special/identity/docs/img/equation_identity_function.svg" alt="Identity function"> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 for all `x`. 39 40 </section> 41 42 <!-- /.intro --> 43 44 <section class="usage"> 45 46 ## Usage 47 48 ```javascript 49 var identity = require( '@stdlib/math/base/special/identity' ); 50 ``` 51 52 #### identity( x ) 53 54 Evaluates the [identity function][identity-function] for a double-precision floating-point number. 55 56 ```javascript 57 var v = identity( -1.0 ); 58 // returns -1.0 59 60 v = identity( 2.0 ); 61 // returns 2.0 62 63 v = identity( 0.0 ); 64 // returns 0.0 65 66 v = identity( -0.0 ); 67 // returns -0.0 68 69 v = identity( NaN ); 70 // returns NaN 71 ``` 72 73 </section> 74 75 <!-- /.usage --> 76 77 <section class="examples"> 78 79 ## Examples 80 81 <!-- eslint no-undef: "error" --> 82 83 ```javascript 84 var randu = require( '@stdlib/random/base/randu' ); 85 var round = require( '@stdlib/math/base/special/round' ); 86 var identity = require( '@stdlib/math/base/special/identity' ); 87 88 var rand; 89 var i; 90 91 for ( i = 0; i < 100; i++ ) { 92 rand = round( randu() * 100.0 ) - 50.0; 93 console.log( 'identity(%d) = %d', rand, identity( rand ) ); 94 } 95 ``` 96 97 </section> 98 99 <!-- /.examples --> 100 101 <!-- C interface documentation. --> 102 103 * * * 104 105 <section class="c"> 106 107 ## C APIs 108 109 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 110 111 <section class="intro"> 112 113 </section> 114 115 <!-- /.intro --> 116 117 <!-- C usage documentation. --> 118 119 <section class="usage"> 120 121 ### Usage 122 123 ```c 124 #include "stdlib/math/base/special/identity.h" 125 ``` 126 127 #### stdlib_base_identity( x ) 128 129 Evaluates the identity function for a double-precision floating-point number. 130 131 ```c 132 double y = stdlib_base_identity( 2.0 ); 133 // returns 2.0 134 ``` 135 136 The function accepts the following arguments: 137 138 - **x**: `[in] double` input value. 139 140 ```c 141 double stdlib_base_identity( const double x ); 142 ``` 143 144 </section> 145 146 <!-- /.usage --> 147 148 <!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 149 150 <section class="notes"> 151 152 </section> 153 154 <!-- /.notes --> 155 156 <!-- C API usage examples. --> 157 158 <section class="examples"> 159 160 ### Examples 161 162 ```c 163 #include "stdlib/math/base/special/identity.h" 164 #include <stdio.h> 165 166 int main() { 167 double x[] = { 3.14, -3.14, 0.0, 0.0/0.0 }; 168 169 double y; 170 int i; 171 for ( i = 0; i < 4; i++ ) { 172 y = stdlib_base_identity( x[ i ] ); 173 printf( "f(%lf) = %lf\n", x[ i ], y ); 174 } 175 } 176 ``` 177 178 </section> 179 180 <!-- /.examples --> 181 182 </section> 183 184 <!-- /.c --> 185 186 <section class="links"> 187 188 [identity-function]: https://en.wikipedia.org/wiki/Identity_function 189 190 </section> 191 192 <!-- /.links -->