File size: 1,845 Bytes
b1b3bae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#region Translated by Jose Antonio De Santiago-Castillo.

//Translated by Jose Antonio De Santiago-Castillo.
//E-mail:JAntonioDeSantiago@gmail.com
//Website: www.DotNumerics.com
//
//Fortran to C# Translation.
//Translated by:
//F2CSharp Version 0.72 (Dicember 7, 2009)
//Code Optimizations: , assignment operator, for-loop: array indexes
//
#endregion

using System;

namespace DotNumerics.LinearAlgebra.CSEispack
{
    public class CSROOT
    {
    

        #region Dependencies
        
        PYTHAG _pythag; 

        #endregion

        public CSROOT(PYTHAG pythag)
        {
    

            #region Set Dependencies
            
            this._pythag = pythag; 

            #endregion

        }
    
        public CSROOT()
        {
    

            #region Dependencies (Initialization)
            
            PYTHAG pythag = new PYTHAG();

            #endregion


            #region Set Dependencies
            
            this._pythag = pythag; 

            #endregion

        }
        public void Run(double XR, double XI, ref double YR, ref double YI)
        {

            #region Variables
            
            double S = 0; double TR = 0; double TI = 0; 

            #endregion

            // c
            // c     (yr,yi) = complex dsqrt(xr,xi) 
            // c     branch chosen so that yr .ge. 0.0 and sign(yi) .eq. sign(xi)
            // c
            TR = XR;
            TI = XI;
            S = Math.Sqrt(0.5E0 * (this._pythag.Run(TR, TI) + Math.Abs(TR)));
            if (TR >= 0.0E0) YR = S;
            if (TI < 0.0E0) S =  - S;
            if (TR <= 0.0E0) YI = S;
            if (TR < 0.0E0) YR = 0.5E0 * (TI / YI);
            if (TR > 0.0E0) YI = 0.5E0 * (TI / YR);
            return;
        }
    }
}