cnegate.js (1377B)
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 // MAIN // 22 23 /** 24 * Negates a complex number. 25 * 26 * @private 27 * @param {(Array|TypedArray|Object)} out - output array 28 * @param {number} re - real component 29 * @param {number} im - imaginary component 30 * @returns {(Array|TypedArray|Object)} negated components 31 * 32 * @example 33 * var out = new Array( 2 ); 34 * 35 * var v = cnegate( out, -4.2, 5.5 ); 36 * // returns [ 4.2, -5.5 ] 37 * 38 * var bool = ( v === out ); 39 * // returns true 40 * 41 * @example 42 * var out = new Array( 2 ); 43 * var v = cnegate( out, 0.0, 0.0 ); 44 * // returns [ -0.0, -0.0 ] 45 * 46 * @example 47 * var out = new Array( 2 ); 48 * var v = cnegate( out, NaN, NaN ); 49 * // returns [ NaN, NaN ] 50 */ 51 function cnegate( out, re, im ) { 52 out[ 0 ] = -re; 53 out[ 1 ] = -im; 54 return out; 55 } 56 57 58 // EXPORTS // 59 60 module.exports = cnegate;