⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqrt.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.toolbox.jmathlib.matrix;

import jmathlib.core.functions.ExternalElementWiseFunction;

public class sqrt extends ExternalElementWiseFunction
{
    
    public sqrt()
    {
        name = "sqrt";
    }
    
    /**Calculates the sqrt of a complex number
    @param arg = the value as an array of double
    @return the result as an array of double*/ 
    public double[] evaluateValue(double[] arg)
    {
        
        // with thanks to Jim Shapiro <jnshapi@argo.ecte.uswc.uswest.com>
        // adapted from "Numerical Recipies in C" (ISBN 0-521-43108-5)
        // by William H. Press et al

        double[] result = new double[2];
        double   re     = arg[REAL];
        double   im     = arg[IMAG];

        double temp = Math.pow(re, 2) + Math.pow(im, 2);
        double mag  = Math.sqrt(temp);

        if (mag > 0.0) 
        {
            if (re > 0.0) 
            {
                temp =  Math.sqrt(0.5 * (mag + re));

                re =  temp;
                im =  0.5 * im / temp;
            } 
            else 
            {
                temp =  Math.sqrt(0.5 * (mag - re));

                if (im < 0.0) 
                {
                    temp =  -temp;
                }

                re =  0.5 * im / temp;
                im =  temp;
            }
        } 
        else 
        {
            re =  0.0;
            im =  0.0;
        }
        result[REAL] = re;
        result[IMAG] = im;
        
        return result;
    }


}

/*
@GROUP
general
@SYNTAX
answer = sqrt(value)
@DOC
Returns the sqrt of a value.
@EXAMPLES
sqrt(4) = 2
sqrt(9) = 3
@NOTES
@SEE
angle, abs
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -