README.md (2235B)
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 # logaddexp 22 23 > Evaluates the [natural logarithm][@stdlib/math/base/special/ln] of `exp(x) + exp(y)`. 24 25 <section class="intro"> 26 27 Log-domain computations are commonly used to increase accuracy and avoid underflow and overflow when very small or very large numbers are represented directly as limited-precision, floating-point numbers. For example, in statistics, evaluating `logaddexp()` is useful when probabilities are so small as to exceed the normal range of floating-point numbers. 28 29 </section> 30 31 <section class="usage"> 32 33 ## Usage 34 35 ```javascript 36 var logaddexp = require( '@stdlib/math/base/special/logaddexp' ); 37 ``` 38 39 #### logaddexp( x, y ) 40 41 Evaluates the [natural logarithm][@stdlib/math/base/special/ln] of `exp(x) + exp(y)`. 42 43 ```javascript 44 var v = logaddexp( 90.0, 90.0 ); 45 // returns ~90.6931 46 47 v = logaddexp( -20.0, 90.0 ); 48 // returns 90.0 49 50 v = logaddexp( 0.0, -100.0 ); 51 // returns ~3.7201e-44 52 53 v = logaddexp( NaN, 1.0 ); 54 // returns NaN 55 ``` 56 57 </section> 58 59 <!-- /.usage --> 60 61 <section class="examples"> 62 63 ## Examples 64 65 <!-- eslint no-undef: "error" --> 66 67 ```javascript 68 var incrspace = require( '@stdlib/array/incrspace' ); 69 var logaddexp = require( '@stdlib/math/base/special/logaddexp' ); 70 71 var x; 72 var v; 73 var i; 74 var j; 75 76 x = incrspace( -100.0, 100.0, 1.0 ); 77 for ( i = 0; i < x.length; i++ ) { 78 for ( j = i; j < x.length; j++ ) { 79 v = logaddexp( x[ i ], x[ j ] ); 80 console.log( 'x: %d, y: %d, f(x, y): %d', x[ i ], x[ j ], v ); 81 } 82 } 83 ``` 84 85 </section> 86 87 <!-- /.examples --> 88 89 <section class="links"> 90 91 [@stdlib/math/base/special/ln]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/ln 92 93 </section> 94 95 <!-- /.links -->