time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (2534B)


      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 # Binary Logarithm
     22 
     23 > Evaluate the [binary logarithm][binary-logarithm].
     24 
     25 <section class="intro">
     26 
     27 The [binary logarithm][binary-logarithm] (logarithm with base 2) is defined for any positive real number as
     28 
     29 <!-- <equation class="equation" label="eq:binary_logarithm" align="center" raw="\quad \log_{2} \left( x \right) = y \quad \text{such that} \quad 2^y = x" alt="Equation for the binary logarithm."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="\quad \log_{2} \left( x \right) = y \quad \text{such that} \quad 2^y = x" data-equation="eq:binary_logarithm">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@8cb4d022f6163be6523964802725ed2a74f2497b/lib/node_modules/@stdlib/math/base/special/log2/docs/img/equation_binary_logarithm.svg" alt="Equation for the binary logarithm.">
     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 log2 = require( '@stdlib/math/base/special/log2' );
     48 ```
     49 
     50 #### log2( x )
     51 
     52 Evaluates the [binary logarithm][binary-logarithm].
     53 
     54 ```javascript
     55 var v = log2( 4.0 );
     56 // returns 2.0
     57 
     58 v = log2( 0.0 );
     59 // returns -Infinity
     60 
     61 v = log2( Infinity );
     62 // returns Infinity
     63 
     64 v = log2( NaN );
     65 // returns NaN
     66 ```
     67 
     68 For negative numbers, the [binary logarithm][binary-logarithm] is **not** defined.
     69 
     70 ```javascript
     71 var v = log2( -4.0 );
     72 // returns NaN
     73 ```
     74 
     75 </section>
     76 
     77 <!-- /.usage -->
     78 
     79 <section class="examples">
     80 
     81 ## Examples
     82 
     83 <!-- eslint no-undef: "error" -->
     84 
     85 ```javascript
     86 var randu = require( '@stdlib/random/base/randu' );
     87 var round = require( '@stdlib/math/base/special/round' );
     88 var log2 = require( '@stdlib/math/base/special/log2' );
     89 
     90 var x;
     91 var i;
     92 
     93 for ( i = 0; i < 100; i++ ) {
     94     x = round( randu() * 100.0 );
     95     console.log( 'log2(%d) = %d', x, log2( x ) );
     96 }
     97 ```
     98 
     99 </section>
    100 
    101 <!-- /.examples -->
    102 
    103 <section class="links">
    104 
    105 [binary-logarithm]: https://en.wikipedia.org/wiki/Binary_logarithm
    106 
    107 </section>
    108 
    109 <!-- /.links -->