github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/lapack/gonum/dcombssq.go (about)

     1  // Copyright ©2019 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gonum
     6  
     7  import "math"
     8  
     9  // Dcombssq adds two scaled sum-of-squares quantities, V := V1 + V2,
    10  //  V_scale^2 * V_ssq := V1_scale^2 * V1_ssq + V2_scale^2 * V2_ssq
    11  // and returns the result V.
    12  //
    13  // Dcombssq is an internal routine. It is exported for testing purposes.
    14  func (Implementation) Dcombssq(scale1, ssq1, scale2, ssq2 float64) (scale, ssq float64) {
    15  	if scale1 >= scale2 {
    16  		if scale1 != 0 {
    17  			return scale1, ssq1 + (scale2/scale1)*(scale2/scale1)*ssq2
    18  		}
    19  		// Both scales are zero.
    20  		if math.IsNaN(ssq1) || math.IsNaN(ssq2) {
    21  			return 0, math.NaN()
    22  		}
    23  		return 0, 0
    24  	}
    25  	return scale2, ssq2 + (scale1/scale2)*(scale1/scale2)*ssq1
    26  }