time-to-botec

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

internal_compreal.js (1395B)


      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 * Computes the real part of the quotient.
     25 *
     26 * ## Notes
     27 *
     28 * -   See figure 10 of [reference][@baudin:2012].
     29 *
     30 * [@baudin:2012]: https://arxiv.org/abs/1210.4539
     31 *
     32 * @private
     33 * @param {number} re1 - real component
     34 * @param {number} im1 - imaginary component
     35 * @param {number} re2 - real component
     36 * @param {number} im2 - imaginary component
     37 * @param {number} r - partial result
     38 * @param {number} t - partial result
     39 * @returns {number} real part of the quotient
     40 */
     41 function internalCompreal( re1, im1, re2, im2, r, t ) {
     42 	var br;
     43 	if ( r === 0.0 ) {
     44 		return ( re1 + (im2 * (im1/re2)) ) * t;
     45 	}
     46 	br = im1 * r;
     47 	if ( br === 0.0 ) {
     48 		return ( re1*t ) + ( (im1*t) * r );
     49 	}
     50 	return ( re1+br ) * t;
     51 }
     52 
     53 
     54 // EXPORTS //
     55 
     56 module.exports = internalCompreal;