time-to-botec

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

reim.js (1536B)


      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 Float64Array = require( '@stdlib/array/float64' );
     24 var Float32Array = require( '@stdlib/array/float32' );
     25 
     26 
     27 // MAIN //
     28 
     29 /**
     30 * Returns the real and imaginary components of a complex number.
     31 *
     32 * @param {Complex} z - complex number
     33 * @returns {(Float64Array|Float32Array)} real and imaginary components
     34 *
     35 * @example
     36 * var Complex128 = require( '@stdlib/complex/float64' );
     37 *
     38 * var z = new Complex128( 5.0, 3.0 );
     39 *
     40 * var out = reim( z );
     41 * // returns <Float64Array>[ 5.0, 3.0 ]
     42 *
     43 * @example
     44 * var Complex64 = require( '@stdlib/complex/float32' );
     45 *
     46 * var z = new Complex64( 5.0, 3.0 );
     47 *
     48 * var out = reim( z );
     49 * // returns <Float32Array>[ 5.0, 3.0 ]
     50 */
     51 function reim( z ) {
     52 	var out;
     53 	if ( z.BYTES_PER_ELEMENT === 4 ) {
     54 		out = new Float32Array( 2 );
     55 	} else {
     56 		out = new Float64Array( 2 );
     57 	}
     58 	out[ 0 ] = z.re;
     59 	out[ 1 ] = z.im;
     60 	return out;
     61 }
     62 
     63 
     64 // EXPORTS //
     65 
     66 module.exports = reim;