time-to-botec

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

cround.js (1591B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var round = require( './../../../../base/special/round' );
     24 
     25 
     26 // MAIN //
     27 
     28 /**
     29 * Rounds a complex number to the nearest integer.
     30 *
     31 * @private
     32 * @param {(Array|TypedArray|Object)} out - output array
     33 * @param {number} re - real component
     34 * @param {number} im - imaginary component
     35 * @returns {(Array|TypedArray|Object)} rounded components
     36 *
     37 * @example
     38 * var out = new Array( 2 );
     39 *
     40 * var v = cround( out, -4.2, 5.5 );
     41 * // returns [ -4.0, 6.0 ]
     42 *
     43 * var bool = ( v === out );
     44 * // returns true
     45 *
     46 * @example
     47 * var out = new Array( 2 );
     48 * var v = cround( out, 9.99999, 0.1 );
     49 * // returns [ 10.0, 0.0 ]
     50 *
     51 * @example
     52 * var out = new Array( 2 );
     53 * var v = cround( out, 0.0, 0.0 );
     54 * // returns [ 0.0, 0.0 ]
     55 *
     56 * @example
     57 * var out = new Array( 2 );
     58 * var v = cround( out, NaN, NaN );
     59 * // returns [ NaN, NaN ]
     60 */
     61 function cround( out, re, im ) {
     62 	out[ 0 ] = round( re );
     63 	out[ 1 ] = round( im );
     64 	return out;
     65 }
     66 
     67 
     68 // EXPORTS //
     69 
     70 module.exports = cround;