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