time-to-botec

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

README.md (2342B)


      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 # Copysign
     22 
     23 > Return a [double-precision floating-point number][ieee754] with the magnitude of `x` and the sign of `y`.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var copysign = require( '@stdlib/math/base/special/copysign' );
     31 ```
     32 
     33 #### copysign( x, y )
     34 
     35 Returns a [double-precision floating-point number][ieee754] with the magnitude of `x` and the sign of `y`.
     36 
     37 ```javascript
     38 var z = copysign( -3.14, 10.0 );
     39 // returns 3.14
     40 
     41 z = copysign( 3.14, -1.0 );
     42 // returns -3.14
     43 
     44 z = copysign( 1.0, -0.0 );
     45 // returns -1.0
     46 
     47 z = copysign( -3.14, -0.0 );
     48 // returns -3.14
     49 
     50 z = copysign( -0.0, 1.0 );
     51 // returns 0.0
     52 ```
     53 
     54 </section>
     55 
     56 <!-- /.usage -->
     57 
     58 <section class="notes">
     59 
     60 ## Notes
     61 
     62 -   According to the [IEEE754][ieee754] standard, a `NaN` has a biased exponent equal to `2047`, a significand greater than `0`, and a sign bit equal to **either** `1` **or** `0`. In which case, `NaN` may not correspond to just one but many binary representations. Accordingly, care should be taken to ensure that `y` is **not** `NaN`, else behavior may be indeterminate.
     63 
     64 </section>
     65 
     66 <!-- /.notes -->
     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 copysign = require( '@stdlib/math/base/special/copysign' );
     77 
     78 var x;
     79 var y;
     80 var z;
     81 var i;
     82 
     83 // Generate random double-precision floating-point numbers `x` and `y` and copy the sign of `y` to `x`...
     84 for ( i = 0; i < 100; i++ ) {
     85     x = (randu()*100.0) - 50.0;
     86     y = (randu()*10.0) - 5.0;
     87     z = copysign( x, y );
     88     console.log( 'x: %d, y: %d => %d', x, y, z );
     89 }
     90 ```
     91 
     92 </section>
     93 
     94 <!-- /.examples -->
     95 
     96 <section class="links">
     97 
     98 [ieee754]: https://en.wikipedia.org/wiki/IEEE_754-1985
     99 
    100 </section>
    101 
    102 <!-- /.links -->