当前位置: 首页>>代码示例>>C#>>正文


C# Double类代码示例

本文整理汇总了C#中Double的典型用法代码示例。如果您正苦于以下问题:C# Double类的具体用法?C# Double怎么用?C# Double使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Double类属于命名空间,在下文中一共展示了Double类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerifyBinaryMinusResult

        private static void VerifyBinaryMinusResult(Double realFirst, Double imgFirst, Double realSecond, Double imgSecond)
        {
            // Create complex numbers
            Complex cFirst = new Complex(realFirst, imgFirst);
            Complex cSecond = new Complex(realSecond, imgSecond);

            // calculate the expected results
            Double realExpectedResult = realFirst - realSecond;
            Double imgExpectedResult = imgFirst - imgSecond;

            // local varuables
            Complex cResult;

            // arithmetic binary minus operation
            cResult = cFirst - cSecond;

            // verify the result
            if (false == Support.VerifyRealImaginaryProperties(cResult, realExpectedResult, imgExpectedResult))
            {
                Console.WriteLine("ErRoR! Binary Minus Error!");
                Console.WriteLine("Binary Minus test = ({0}, {1}) - ({2}, {3})", realFirst, imgFirst, realSecond, imgSecond);
                Assert.True(false, "Verification Failed");
            }

            // arithmetic substract operation
            cResult = Complex.Subtract(cFirst, cSecond);

            // verify the result
            if (false == Support.VerifyRealImaginaryProperties(cResult, realExpectedResult, imgExpectedResult))
            {
                Console.WriteLine("ErRoR! Substract Error!");
                Console.WriteLine("Substract test = ({0}, {1}) - ({2}, {3})", realFirst, imgFirst, realSecond, imgSecond);
                Assert.True(false, "Verification Failed");
            }
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:35,代码来源:arithmaticOperation_BinaryMinus_Subtract.cs

示例2: ToDouble

 public static Double ToDouble(string valueToParse, Double defaultValue)
 {
     Double returnValue;
     if (!Double.TryParse(valueToParse, out returnValue))
         returnValue = defaultValue;
     return returnValue;
 }
开发者ID:benjaminaaron,项目名称:SumoVizUnity_ModSem,代码行数:7,代码来源:TryParseWithDefault.cs

示例3: Main

    static void Main(String[] args)
    {
        Console.WriteLine("Enter numbers separated by comma: ");
          string lineofnumbers = Console.ReadLine();

          string answer = "default";
          while(true)
        {
          Console.WriteLine("Default is sorting by ascending order. Sort by descending order ? (y, n): ");
          answer = Console.ReadLine();
          if("y" == answer)
        {
          Console.WriteLine("Yes");
          break;
        }
          else
        {
          Console.WriteLine("Default");
          break;
        }
        }
          string[] tokens = lineofnumbers.Split(',');

          Double[] array = new Double[tokens.Length];

          for(int i = 0; i < tokens.Length; i++)
        array[i] = Double.Parse(tokens[i]);

          double[] sorted = QuickSort(array, 0, array.Length - 1);
          foreach(Double i in sorted)
        Console.WriteLine(i);
    }
开发者ID:pasoev,项目名称:praxis,代码行数:32,代码来源:sort-reverse.cs

示例4: Calculate

    protected void Calculate(object sender, EventArgs e)
    {
        Double resistance = 0;

        // Tracks
        width = ToMicrons (WidthEntry.Text, WidthCombo);
        thickness = ToMicrons (ThicknessEntry.Text, ThicknessCombo);
        length = ToMicrons (LengthEntry.Text, LengthCombo);

        // Vias
        vias = -1;
        if (ViaEntry.Text != "") {
            if (Int32.TryParse (ViaEntry.Text, out vias)) {
                plating = ToMicrons (PlatingEntry.Text, PlatingCombo);
                diameter = ToMicrons (DrillEntry.Text, DrillCombo);
                via_length = ToMicrons (ViaLengthEntry.Text, ViaLengthCombo);
            }
        } else
            vias = 0;

        // Calculate and display resistance
        if (ValuesValid ()) {
            resistance = rho_foil * length / (width * thickness);
            if (vias > 0){
                Double radius = diameter / 2.0;
                Double area = (Math.PI * Math.Pow(radius,2.0)) - (Math.PI * Math.Pow(radius-plating, 2.0));
                resistance += vias * rho_plated * via_length / area;
            }
            ResistanceLabel.Text = String.Format ("Resistance = {0:G4} Ω", resistance);
        }
        else
            ResistanceLabel.Text = "Error";
    }
开发者ID:morefun0302,项目名称:WPC,代码行数:33,代码来源:MainWindow.cs

示例5: OnProgress

 public static Int32 OnProgress(Object extraData, Double dlTotal,
     Double dlNow, Double ulTotal, Double ulNow)
 {
     Console.WriteLine("Progress: {0} {1} {2} {3}",
         dlTotal, dlNow, ulTotal, ulNow);
     return 0; // standard return from PROGRESSFUNCTION
 }
开发者ID:pjquirk,项目名称:libcurl.NET,代码行数:7,代码来源:Upload.cs

示例6: VerifySqrtWithRectangularForm

        private static void VerifySqrtWithRectangularForm(Double real, Double imaginary)
        {
            // sqrt(a+bi) = +- (sqrt(r + a) + i sqrt(r - a) sign(b)) sqrt(2) / 2, unless a=-r and y = 0
            Complex complex = new Complex(real, imaginary);

            Double expectedReal = 0.0;
            Double expectedImaginary = 0.0;

            if (0 == imaginary)
            {
                if (real == -complex.Magnitude)
                    expectedImaginary = Math.Sqrt(-real);
                else
                    expectedReal = Math.Sqrt(real);
            }
            else
            {
                Double scale = 1 / Math.Sqrt(2);
                expectedReal = scale * Math.Sqrt(complex.Magnitude + complex.Real);
                expectedImaginary = scale * Math.Sqrt(complex.Magnitude - complex.Real);
                if (complex.Imaginary < 0)
                {
                    expectedImaginary = -expectedImaginary;
                }
            }
            VerifySqrtWithRectangularForm(real, imaginary, expectedReal, expectedImaginary);
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:27,代码来源:standardNumericalFunctions_Sqrt.cs

示例7: init

 public String init()
 {
     this.sof = 0.0;
     this.drivercount = 0;
     this.points = new List<Double>();
     return "sof";
 }
开发者ID:Jeffg24,项目名称:irtvo,代码行数:7,代码来源:sof.cs

示例8: VerifyBinaryPlusResult

        private static void VerifyBinaryPlusResult(Double realFirst, Double imgFirst, Double realSecond, Double imgSecond)
        {
            // Create complex numbers
            Complex cFirst = new Complex(realFirst, imgFirst);
            Complex cSecond = new Complex(realSecond, imgSecond);

            // calculate the expected results
            Double realExpectedResult = realFirst + realSecond;
            Double imgExpectedResult = imgFirst + imgSecond;

            //local variable
            Complex cResult;

            // arithmetic addition operation
            cResult = cFirst + cSecond;

            // verify the result
            if (!Support.VerifyRealImaginaryProperties(cResult, realExpectedResult, imgExpectedResult))
            {
                Console.WriteLine("ErRoR! Binary Plus Error!");
                Console.WriteLine("Binary Plus test = ({0}, {1}) + ({2}, {3})", realFirst, imgFirst, realSecond, imgSecond);
                Assert.True(false, "Verification Failed");
            }

            // arithmetic static addition operation
            cResult = Complex.Add(cFirst, cSecond);

            // verify the result
            if (!Support.VerifyRealImaginaryProperties(cResult, realExpectedResult, imgExpectedResult))
            {
                Console.WriteLine("ErRoR! Add Error!");
                Console.WriteLine("Add test = ({0}, {1}) + ({2}, {3})", realFirst, imgFirst, realSecond, imgSecond);
                Assert.True(false, "Verification Failed");
            }
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:35,代码来源:arithmaticOperation_BinaryPlus_Add.cs

示例9: QuickSort

 public static Double[] QuickSort(Double[] a, Double left, Double right)
 {
     Double i = left;
       Double j = right;
       Double randcentre = ((left + right) / 2);
       Double x = a[Convert.ToInt32(randcentre)];
       Double w = 0;
       while (i <= j)
     {
       while (a[Convert.ToInt32(i)] < x)
     {
       i++;
     }
       while (x < a[Convert.ToInt32(j)])
     {
       j--;
     }
       if (i <= j)
     {
       w = a[Convert.ToInt32(i)];
       a[Convert.ToInt32(i++)] = a[Convert.ToInt32(j)];
       a[Convert.ToInt32(j--)] = w;
     }
     }
       if (left < j)
     {
       QuickSort(a, left, j);
     }
       if (i < right)
     {
       QuickSort(a, i, right);
     }
       return a;
 }
开发者ID:pasoev,项目名称:praxis,代码行数:34,代码来源:sort.cs

示例10: Div

    public static Vector3 Div(Vector3 v1, Double _x)
    {
        v1.x /= (float)_x;
        v1.z /= (float)_x;

        return v1;
    }
开发者ID:Ashen-Vaults,项目名称:Unity-Path-Finder,代码行数:7,代码来源:AIMovement.cs

示例11: RunTests_PowComplex

        private static void RunTests_PowComplex(Double a, Double b)
        {
            //if (!Support.IsARM || !m_randomValues)
            //{
            //	VerifyPow(a, b, -1.0, 0.0);
            //}
            VerifyPow(a, b, 0.0, -1.0);
            VerifyPow(a, b, 0.0, 0.0);
            VerifyPow(a, b, 0.0, 1.0);
            VerifyPow(a, b, 1.0, 0.0);

            Double real = Support.GetSmallRandomDoubleValue(false);
            Double imaginary = Support.GetSmallRandomDoubleValue(false);
            VerifyPow(a, b, real, imaginary);

            real = Support.GetSmallRandomDoubleValue(true);
            imaginary = Support.GetSmallRandomDoubleValue(false);
            VerifyPow(a, b, real, imaginary);

            real = Support.GetSmallRandomDoubleValue(true);
            imaginary = Support.GetSmallRandomDoubleValue(true);
            VerifyPow(a, b, real, imaginary);

            real = Support.GetSmallRandomDoubleValue(false);
            imaginary = Support.GetSmallRandomDoubleValue(true);
            VerifyPow(a, b, real, imaginary);
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:27,代码来源:standardNumericalFunctions_Pow.cs

示例12: VerifyExpWithAddition

        private static void VerifyExpWithAddition(Double real, Double imaginary)
        {
            // verify with e(x+y) = e(x)*e(y) if xy == yx
            Complex realComplex = new Complex(real, 0.0);
            Complex imgComplex = new Complex(0.0, imaginary);

            Complex ri = realComplex * imgComplex;
            Complex ir = imgComplex * realComplex;
            if (!ri.Equals(ir))
            {
                return;
            }

            Complex realExp = Complex.Exp(realComplex);
            Complex imgExp = Complex.Exp(imgComplex);
            Complex expectedExp = realExp * imgExp;

            Complex complex = new Complex(real, imaginary);
            Complex complexExp = Complex.Exp(complex);

            if (false == Support.VerifyRealImaginaryProperties(complexExp, expectedExp.Real, expectedExp.Imaginary))
            {
                Console.WriteLine("Error eXp-Err3521! Exp({0}):{1} != {2})", complex, complexExp, expectedExp);
                Assert.True(false, "Verification Failed");
            }
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:26,代码来源:standardNumericalFunctions_Exp.cs

示例13: startTimer

 public void startTimer(Double seconds)
 {
     Timer gameTimer = new Timer();
     gameTimer.Elapsed += new ElapsedEventHandler(TimerGameEvent);
     gameTimer.Interval = seconds;
     gameTimer.Enabled = true;
 }
开发者ID:marianspoiala,项目名称:RollEm,代码行数:7,代码来源:GameUtils.cs

示例14: VerifyPow

        private static void VerifyPow(Double a, Double b, Double doubleVal)
        {
            Complex x = new Complex(a, b);
            Complex powComplex = Complex.Pow(x, doubleVal);

            Double expectedReal = 0;
            Double expectedImaginary = 0;
            if (0 == doubleVal)
                expectedReal = 1;
            else if (!(0 == a && 0 == b))
            {
                //pow(x, y) = exp(y·log(x))
                Complex y = new Complex(doubleVal, 0);
                Complex expected = Complex.Exp(y * Complex.Log(x));
                expectedReal = expected.Real;
                expectedImaginary = expected.Imaginary;
            }

            if (false == Support.VerifyRealImaginaryProperties(powComplex, expectedReal, expectedImaginary))
            {
                Console.WriteLine("Error pOw-Err2534! Pow (({0}, {1}), {2})", a, b, doubleVal);

                Assert.True(false, "Verification Failed");
            }
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:25,代码来源:standardNumericalFunctions_Pow.cs

示例15: VerifyBinaryMultiplyResult

        private static void VerifyBinaryMultiplyResult(Double realFirst, Double imgFirst, Double realSecond, Double imgSecond)
        {
            // calculate the expected results
            Double realExpectedResult = realFirst * realSecond - imgFirst * imgSecond;
            Double imaginaryExpectedResult = realFirst * imgSecond + imgFirst * realSecond;

            // Create complex numbers
            Complex cFirst = new Complex(realFirst, imgFirst);
            Complex cSecond = new Complex(realSecond, imgSecond);

            // arithmetic multiply (binary) operation
            Complex cResult = cFirst * cSecond;

            // verify the result
            if (false == Support.VerifyRealImaginaryProperties(cResult, realExpectedResult, imaginaryExpectedResult))
            {
                Console.WriteLine("ErRoR! Binary Multiply Error!");
                Console.WriteLine("Binary Multiply test = ({0}, {1}) * ({2}, {3})", realFirst, imgFirst, realSecond, imgSecond);
                Assert.True(false, "Verification Failed");
            }

            // arithmetic multiply (static) operation
            cResult = Complex.Multiply(cFirst, cSecond);

            // verify the result
            if (false == Support.VerifyRealImaginaryProperties(cResult, realExpectedResult, imaginaryExpectedResult))
            {
                Console.WriteLine("ErRoR! Multiply (Static) Error!");
                Console.WriteLine("Multiply (Static) test = ({0}, {1}) * ({2}, {3})", realFirst, imgFirst, realSecond, imgSecond);
                Assert.True(false, "Verification Failed");
            }
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:32,代码来源:arithmaticOperation_BinaryMultiply_Multiply.cs


注:本文中的Double类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。