README.md (3282B)
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 # Exponential Function 22 23 > [Exponential function][exponential-function]. 24 25 <section class="intro"> 26 27 The [exponential function][exponential-function] is defined as 28 29 <!-- <equation class="equation" label="eq:exponential_function" align="center" raw="y = b^x" alt="Exponential function"> --> 30 31 <div class="equation" align="center" data-raw-text="y = b^x" data-equation="eq:exponential_function"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@c1bdd27898df04d752ddb2dca37ca049e4c94d9b/lib/node_modules/@stdlib/math/base/special/fast/pow-int/docs/img/equation_exponential_function.svg" alt="Exponential function"> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 where `b` is the **base** and `x` is the **exponent**. 39 40 </section> 41 42 <!-- /.intro --> 43 44 <section class="usage"> 45 46 ## Usage 47 48 ```javascript 49 var pow = require( '@stdlib/math/base/special/fast/pow-int' ); 50 ``` 51 52 #### pow( base, exponent ) 53 54 Evaluates the [exponential function][exponential-function] given a signed 32-bit integer `exponent`. 55 56 ```javascript 57 var v = pow( 2.0, 3 ); 58 // returns 8.0 59 60 v = pow( 100.0, 0 ); 61 // returns 1.0 62 63 v = pow( 3.14, 1 ); 64 // returns 3.14 65 66 v = pow( -3.14, 1 ); 67 // returns -3.14 68 69 v = pow( 2.0, -2 ); 70 // returns 0.25 71 72 v = pow( NaN, 3 ); 73 // returns NaN 74 ``` 75 76 </section> 77 78 <!-- /.usage --> 79 80 <section class="notes"> 81 82 ## Notes 83 84 - This implementation is **not** recommended for high-precision applications due to error accumulation. As a trivial example, consider 85 86 ```javascript 87 var v = pow( 10.0, 308 ); 88 // returns 1.0000000000000006e+308 89 ``` 90 91 where the expected result is `1.0e+308`. 92 93 - If provided a negative `exponent`, the implementation first computes the reciprocal of the `base` and then evaluates the exponential function. This can introduce significant error. For example, 94 95 ```javascript 96 var v = pow( -459, -98 ); 97 // returns 1.3878956588399783e-261 98 ``` 99 100 where the expected result is `1.3878956588399598e-261`. From the bit sequences, 101 102 ```text 103 0000100111000101110110100000000111001011001011010001000101010110 104 0000100111000101110110100000000111001011001011010001000100000100 105 ``` 106 107 one observes that the returned value differs in the last `7` bits of the significand. 108 109 </section> 110 111 <!-- /.notes --> 112 113 <section class="examples"> 114 115 ## Examples 116 117 <!-- eslint no-undef: "error" --> 118 119 ```javascript 120 var pow = require( '@stdlib/math/base/special/fast/pow-int' ); 121 122 var x; 123 var y; 124 var v; 125 126 x = 10.0; 127 for ( y = 0; y < 309; y++ ) { 128 v = pow( x, y ); 129 console.log( '%d^%d = %d', x, y, v ); 130 } 131 ``` 132 133 </section> 134 135 <!-- /.examples --> 136 137 <section class="links"> 138 139 [exponential-function]: https://en.wikipedia.org/wiki/Exponential_function 140 141 </section> 142 143 <!-- /.links -->