README.md (1926B)
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 # log1p 22 23 > Evaluate the [natural logarithm][@stdlib/math/base/special/ln] of `1+x`. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var log1p = require( '@stdlib/math/base/special/log1p' ); 31 ``` 32 33 #### log1p( x ) 34 35 Evaluates the [natural logarithm][@stdlib/math/base/special/ln] of `1+x`. 36 37 ```javascript 38 var v = log1p( 4.0 ); 39 // returns ~1.609 40 41 v = log1p( -1.0 ); 42 // returns -Infinity 43 44 v = log1p( Infinity ); 45 // returns Infinity 46 47 v = log1p( 0.0 ); 48 // returns 0.0 49 50 v = log1p( -0.0 ); 51 // returns -0.0 52 53 v = log1p( NaN ); 54 // returns NaN 55 ``` 56 57 For `x < -1`, the function returns `NaN`, as the [natural logarithm][@stdlib/math/base/special/ln] is **not** defined for negative numbers. 58 59 ```javascript 60 var v = log1p( -2.0 ); 61 // returns NaN 62 ``` 63 64 </section> 65 66 <!-- /.usage --> 67 68 <section class="examples"> 69 70 ## Examples 71 72 <!-- eslint no-undef: "error" --> 73 74 ```javascript 75 var randu = require( '@stdlib/random/base/randu' ); 76 var round = require( '@stdlib/math/base/special/round' ); 77 var log1p = require( '@stdlib/math/base/special/log1p' ); 78 79 var x; 80 var i; 81 82 for ( i = 0; i < 100; i++ ) { 83 x = round( randu() * 100.0 ); 84 console.log( log1p( x ) ); 85 } 86 ``` 87 88 </section> 89 90 <!-- /.examples --> 91 92 <section class="links"> 93 94 [@stdlib/math/base/special/ln]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/ln 95 96 </section> 97 98 <!-- /.links -->