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