cis.js (1439B)
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 sincos = require( './../../../../base/special/sincos' ); 24 var exp = require( './../../../../base/special/exp' ); 25 26 27 // MAIN // 28 29 /** 30 * Computes the cis function of a complex number. 31 * 32 * @private 33 * @param {(Array|TypedArray|Object)} out - output array 34 * @param {number} re - real component 35 * @param {number} im - imaginary component 36 * @returns {(Array|TypedArray|Object)} output array 37 * 38 * @example 39 * var out = [ 0.0, 0.0 ]; 40 * 41 * var v = cis( out, 1.0, 0.0 ); 42 * // returns [ ~0.540, ~0.841 ] 43 * 44 * var bool = ( v === out ); 45 * // returns true 46 */ 47 function cis( out, re, im ) { 48 var tmp; 49 var e; 50 51 sincos( out, re ); 52 tmp = out[ 0 ]; 53 if ( im !== 0.0 ) { 54 e = exp( -im ); 55 tmp *= e; 56 out[ 1 ] *= e; 57 } 58 out[ 0 ] = out[ 1 ]; 59 out[ 1 ] = tmp; 60 return out; 61 } 62 63 64 // EXPORTS // 65 66 module.exports = cis;