time-to-botec

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

README.md (2309B)


      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 # modf
     22 
     23 > Decompose a [double-precision floating-point number][ieee754] into integral and fractional parts.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var modf = require( '@stdlib/math/base/special/modf' );
     31 ```
     32 
     33 #### modf( \[out,] x )
     34 
     35 Decomposes a [double-precision floating-point number][ieee754] into integral and fractional parts, each having the same type and sign as `x`.
     36 
     37 ```javascript
     38 var parts = modf( 3.14 );
     39 // returns [ 3.0, 0.14000000000000012 ]
     40 
     41 parts = modf( +0.0 );
     42 // returns [ +0.0, +0.0 ]
     43 
     44 parts = modf( -0.0 );
     45 // returns [ -0.0, -0.0 ]
     46 
     47 parts = modf( Infinity );
     48 // returns [ Infinity, +0.0 ]
     49 
     50 parts = modf( -Infinity );
     51 // returns [ -Infinity, -0.0 ]
     52 
     53 parts = modf( NaN );
     54 // returns [ NaN, NaN ]
     55 ```
     56 
     57 To avoid unnecessary memory allocation, the function supports providing an output (destination) object.
     58 
     59 ```javascript
     60 var Float64Array = require( '@stdlib/array/float64' );
     61 
     62 var out = new Float64Array( 2 );
     63 
     64 var parts = modf( out, 3.14 );
     65 // returns <Float64Array>[ 3.0, 0.14000000000000012 ]
     66 
     67 var bool = ( parts === out );
     68 // returns true
     69 ```
     70 
     71 </section>
     72 
     73 <!-- /.usage -->
     74 
     75 <section class="notes">
     76 
     77 </section>
     78 
     79 <!-- /.notes -->
     80 
     81 <section class="examples">
     82 
     83 ## Examples
     84 
     85 <!-- eslint no-undef: "error" -->
     86 
     87 ```javascript
     88 var randu = require( '@stdlib/random/base/randu' );
     89 var modf = require( '@stdlib/math/base/special/modf' );
     90 
     91 var parts;
     92 var x;
     93 var i;
     94 
     95 for ( i = 0; i < 100; i++ ) {
     96     x = (randu()*1000.0) - 500.0;
     97     parts = modf( x );
     98     console.log( 'modf(%d) => integral: %d. fraction: %d.', x, parts[ 0 ], parts[ 1 ] );
     99 }
    100 ```
    101 
    102 </section>
    103 
    104 <!-- /.examples -->
    105 
    106 <section class="links">
    107 
    108 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
    109 
    110 </section>
    111 
    112 <!-- /.links -->