diff --git a/src/Numerics/Complex32.cs b/src/Numerics/Complex32.cs index 913a05d4..a9dce14c 100644 --- a/src/Numerics/Complex32.cs +++ b/src/Numerics/Complex32.cs @@ -1,9 +1,7 @@ // // Math.NET Numerics, part of the Math.NET Project // http://mathnet.opensourcedotnet.info -// // Copyright (c) 2009-2010 Math.NET -// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,10 +10,8 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: -// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -131,8 +127,8 @@ namespace MathNet.Numerics #endif public Complex32(float real, float imaginary) { - _real = real; - _imag = imaginary; + this._real = real; + this._imag = imaginary; } #endregion @@ -153,7 +149,10 @@ namespace MathNet.Numerics /// A value representing the infinity value. public static Complex32 Infinity { - get { return _infinity; } + get + { + return _infinity; + } } /// @@ -162,7 +161,10 @@ namespace MathNet.Numerics /// A value representing not-a-number. public static Complex32 NaN { - get { return _nan; } + get + { + return _nan; + } } /// @@ -171,7 +173,10 @@ namespace MathNet.Numerics /// A value representing the imaginary unit number. public static Complex32 ImaginaryOne { - get { return _i; } + get + { + return _i; + } } /// @@ -180,7 +185,10 @@ namespace MathNet.Numerics /// A value representing the zero value. public static Complex32 Zero { - get { return new Complex32(0.0f, 0.0f); } + get + { + return new Complex32(0.0f, 0.0f); + } } /// @@ -189,7 +197,10 @@ namespace MathNet.Numerics /// A value representing the 1 value. public static Complex32 One { - get { return _one; } + get + { + return _one; + } } #endregion Properties @@ -203,8 +214,10 @@ namespace MathNet.Numerics #if !SILVERLIGHT [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] #endif - - get { return _real; } + get + { + return this._real; + } } /// @@ -216,84 +229,86 @@ namespace MathNet.Numerics #if !SILVERLIGHT [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] #endif - - get { return _imag; } + get + { + return this._imag; + } } /// /// Gets a value indicating whether the Complex32 is zero. /// - /// true if this instance is zero; otherwise, false. + /// true if this instance is zero; otherwise, false. public bool IsZero() { - return _real == 0.0f && _imag == 0.0f; + return this._real == 0.0f && this._imag == 0.0f; } /// /// Gets a value indicating whether the Complex32 is one. /// - /// true if this instance is one; otherwise, false. + /// true if this instance is one; otherwise, false. public bool IsOne() { - return _real == 1.0f && _imag == 0.0f; + return this._real == 1.0f && this._imag == 0.0f; } /// /// Gets a value indicating whether the Complex32 is the imaginary unit. /// - /// true if this instance is ImaginaryOne; otherwise, false. + /// true if this instance is ImaginaryOne; otherwise, false. public bool IsImaginaryOne() { - return _real == 0.0f && _imag == 1.0f; + return this._real == 0.0f && this._imag == 1.0f; } /// /// Gets a value indicating whether the provided Complex32evaluates /// to a value that is not a number. /// - /// + /// /// true if this instance is ; otherwise, /// false. - /// + /// public bool IsNaN() { - return float.IsNaN(_real) || float.IsNaN(_imag); + return float.IsNaN(this._real) || float.IsNaN(this._imag); } /// /// Gets a value indicating whether the provided Complex32 evaluates to an /// infinite value. /// - /// + /// /// true if this instance is infinite; otherwise, false. - /// + /// /// /// True if it either evaluates to a complex infinity /// or to a directed infinity. /// public bool IsInfinity() { - return float.IsInfinity(_real) || float.IsInfinity(_imag); + return float.IsInfinity(this._real) || float.IsInfinity(this._imag); } /// /// Gets a value indicating whether the provided Complex32 is real. /// - /// true if this instance is a real number; otherwise, false. + /// true if this instance is a real number; otherwise, false. public bool IsReal() { - return _imag == 0.0f; + return this._imag == 0.0f; } /// /// Gets a value indicating whether the provided Complex32 is real and not negative, that is >= 0. /// - /// + /// /// true if this instance is real nonnegative number; otherwise, false. - /// + /// public bool IsRealNonNegative() { - return _imag == 0.0f && _real >= 0; + return this._imag == 0.0f && this._real >= 0; } /// @@ -311,85 +326,95 @@ namespace MathNet.Numerics /// a = b.Conjugate /// /// + /// The conjugate of this Complex32 public Complex32 Conjugate() { - return new Complex32(_real, -_imag); + return new Complex32(this._real, -this._imag); } /// /// Gets the magnitude or modulus of this Complex32. /// + /// The magnitude or modulus of this Complex32 /// public float Magnitude { - get { return (float)Math.Sqrt((_real * _real) + (_imag * _imag)); } + get + { + return (float)Math.Sqrt((this._real * this._real) + (this._imag * this._imag)); + } } /// /// Gets the squared magnitude of this Complex32. /// - /// + /// The squared magnitude of this Complex32 public float MagnitudeSquared { - get { return (_real * _real) + (_imag * _imag); } + get + { + return (this._real * this._real) + (this._imag * this._imag); + } } /// - /// Gets phase or argument of this Complex32. + /// Gets the phase or argument of this Complex32. /// /// /// Phase always returns a value bigger than negative Pi and /// smaller or equal to Pi. If this Complex32 is zero, the Complex32 /// is assumed to be positive real with an argument of zero. /// + /// The phase or argument of this Complex32 public float Phase { get { - if (IsReal() && _real < 0) + if (this.IsReal() && this._real < 0) { return (float)Math.PI; } - return IsRealNonNegative() ? 0.0f : (float)Math.Atan2(_imag, _real); + return this.IsRealNonNegative() ? 0.0f : (float)Math.Atan2(this._imag, this._real); } } /// /// Gets the unity of this complex (same argument, but on the unit circle; exp(I*arg)) /// + /// The unity of this Complex32. public Complex32 Sign { get { - if (float.IsPositiveInfinity(_real) && float.IsPositiveInfinity(_imag)) + if (float.IsPositiveInfinity(this._real) && float.IsPositiveInfinity(this._imag)) { return new Complex32((float)Constants.Sqrt1Over2, (float)Constants.Sqrt1Over2); } - if (float.IsPositiveInfinity(_real) && float.IsNegativeInfinity(_imag)) + if (float.IsPositiveInfinity(this._real) && float.IsNegativeInfinity(this._imag)) { return new Complex32((float)Constants.Sqrt1Over2, -(float)Constants.Sqrt1Over2); } - if (float.IsNegativeInfinity(_real) && float.IsPositiveInfinity(_imag)) + if (float.IsNegativeInfinity(this._real) && float.IsPositiveInfinity(this._imag)) { return new Complex32(-(float)Constants.Sqrt1Over2, -(float)Constants.Sqrt1Over2); } - if (float.IsNegativeInfinity(_real) && float.IsNegativeInfinity(_imag)) + if (float.IsNegativeInfinity(this._real) && float.IsNegativeInfinity(this._imag)) { return new Complex32(-(float)Constants.Sqrt1Over2, (float)Constants.Sqrt1Over2); } // don't replace this with "Magnitude"! - var mod = SpecialFunctions.Hypotenuse(_real, _imag); + var mod = SpecialFunctions.Hypotenuse(this._real, this._imag); if (mod == 0.0f) { return Zero; } - return new Complex32((float)(_real / mod), (float)(_imag / mod)); + return new Complex32((float)(this._real / mod), (float)(this._imag / mod)); } } @@ -403,13 +428,13 @@ namespace MathNet.Numerics /// public Complex32 Exponential() { - var exp = (float)Math.Exp(_real); - if (IsReal()) + var exp = (float)Math.Exp(this._real); + if (this.IsReal()) { return new Complex32(exp, 0.0f); } - return new Complex32(exp * (float)Trig.Cosine(_imag), exp * (float)Trig.Sine(_imag)); + return new Complex32(exp * (float)Trig.Cosine(this._imag), exp * (float)Trig.Sine(this._imag)); } /// @@ -420,12 +445,12 @@ namespace MathNet.Numerics /// public Complex32 NaturalLogarithm() { - if (IsRealNonNegative()) + if (this.IsRealNonNegative()) { - return new Complex32((float)Math.Log(_real), 0.0f); + return new Complex32((float)Math.Log(this._real), 0.0f); } - return new Complex32(0.5f * (float)Math.Log(MagnitudeSquared), Phase); + return new Complex32(0.5f * (float)Math.Log(this.MagnitudeSquared), this.Phase); } /// @@ -439,7 +464,7 @@ namespace MathNet.Numerics /// public Complex32 Power(Complex32 exponent) { - if (IsZero()) + if (this.IsZero()) { if (exponent.IsZero()) { @@ -464,7 +489,7 @@ namespace MathNet.Numerics return NaN; } - return (exponent * NaturalLogarithm()).Exponential(); + return (exponent * this.NaturalLogarithm()).Exponential(); } /// @@ -478,7 +503,7 @@ namespace MathNet.Numerics /// public Complex32 Root(Complex32 rootExponent) { - return Power(1 / rootExponent); + return this.Power(1 / rootExponent); } /// @@ -489,12 +514,12 @@ namespace MathNet.Numerics /// public Complex32 Square() { - if (IsReal()) + if (this.IsReal()) { - return new Complex32(_real * _real, 0.0f); + return new Complex32(this._real * this._real, 0.0f); } - return new Complex32((_real * _real) - (_imag * _imag), 2 * _real * _imag); + return new Complex32((this._real * this._real) - (this._imag * this._imag), 2 * this._real * this._imag); } /// @@ -505,32 +530,32 @@ namespace MathNet.Numerics /// public Complex32 SquareRoot() { - if (IsRealNonNegative()) + if (this.IsRealNonNegative()) { - return new Complex32((float)Math.Sqrt(_real), 0.0f); + return new Complex32((float)Math.Sqrt(this._real), 0.0f); } Complex32 result; - var absReal = Math.Abs(Real); - var absImag = Math.Abs(Imaginary); + var absReal = Math.Abs(this.Real); + var absImag = Math.Abs(this.Imaginary); double w; if (absReal >= absImag) { - var ratio = Imaginary / Real; + var ratio = this.Imaginary / this.Real; w = Math.Sqrt(absReal) * Math.Sqrt(0.5 * (1.0f + Math.Sqrt(1.0f + (ratio * ratio)))); } else { - var ratio = Real / Imaginary; + var ratio = this.Real / this.Imaginary; w = Math.Sqrt(absImag) * Math.Sqrt(0.5 * (Math.Abs(ratio) + Math.Sqrt(1.0f + (ratio * ratio)))); } - if (Real >= 0.0f) + if (this.Real >= 0.0f) { - result = new Complex32((float)w, (float)(Imaginary / (2.0f * w))); + result = new Complex32((float)w, (float)(this.Imaginary / (2.0f * w))); } - else if (Imaginary >= 0.0f) + else if (this.Imaginary >= 0.0f) { result = new Complex32((float)(absImag / (2.0 * w)), (float)w); } @@ -599,7 +624,7 @@ namespace MathNet.Numerics /// public override string ToString() { - return ToString(null, null); + return this.ToString(null, null); } /// @@ -614,7 +639,7 @@ namespace MathNet.Numerics /// public string ToString(string format) { - return ToString(format, null); + return this.ToString(format, null); } /// @@ -629,7 +654,7 @@ namespace MathNet.Numerics /// public string ToString(IFormatProvider formatProvider) { - return ToString(null, formatProvider); + return this.ToString(null, formatProvider); } /// @@ -655,28 +680,28 @@ namespace MathNet.Numerics { var numberFormatInfo = formatProvider.GetNumberFormatInfo(); - if (IsNaN()) + if (this.IsNaN()) { return numberFormatInfo.NaNSymbol; } - if (IsInfinity()) + if (this.IsInfinity()) { return numberFormatInfo.PositiveInfinitySymbol; } var ret = new StringBuilder(); - if (_real != 0.0f) + if (this._real != 0.0f) { - ret.Append(_real.ToString(format, formatProvider)); + ret.Append(this._real.ToString(format, formatProvider)); } - if (_imag != 0.0f) + if (this._imag != 0.0f) { - if (_real != 0.0f) + if (this._real != 0.0f) { - if (_imag < 0) + if (this._imag < 0) { ret.Append(" "); } @@ -686,7 +711,7 @@ namespace MathNet.Numerics } } - ret.Append(_imag.ToString(format, formatProvider)).Append("i"); + ret.Append(this._imag.ToString(format, formatProvider)).Append("i"); } if (ret.Length == 0) @@ -714,17 +739,17 @@ namespace MathNet.Numerics /// public bool Equals(Complex32 other) { - if (IsNaN() || other.IsNaN()) + if (this.IsNaN() || other.IsNaN()) { return false; } - if (IsInfinity() && other.IsInfinity()) + if (this.IsInfinity() && other.IsInfinity()) { return true; } - return _real.AlmostEqual(other._real) && _imag.AlmostEqual(other._imag); + return this._real.AlmostEqual(other._real) && this._imag.AlmostEqual(other._imag); } /// @@ -739,7 +764,7 @@ namespace MathNet.Numerics /// public override int GetHashCode() { - return _real.GetHashCode() ^ (-_imag.GetHashCode()); + return this._real.GetHashCode() ^ (-this._imag.GetHashCode()); } /// @@ -755,7 +780,7 @@ namespace MathNet.Numerics /// public override bool Equals(object obj) { - return (obj is Complex32) && Equals((Complex32)obj); + return (obj is Complex32) && this.Equals((Complex32)obj); } #endregion @@ -865,7 +890,7 @@ namespace MathNet.Numerics public static Complex32 operator *(Complex32 multiplicand, Complex32 multiplier) { return new Complex32( - (multiplicand._real * multiplier._real) - (multiplicand._imag * multiplier._imag), + (multiplicand._real * multiplier._real) - (multiplicand._imag * multiplier._imag), (multiplicand._real * multiplier._imag) + (multiplicand._imag * multiplier._real)); } @@ -900,7 +925,7 @@ namespace MathNet.Numerics var modSquared = divisor.MagnitudeSquared; return new Complex32( - ((dividend._real * divisor._real) + (dividend._imag * divisor._imag)) / modSquared, + ((dividend._real * divisor._real) + (dividend._imag * divisor._imag)) / modSquared, ((dividend._imag * divisor._real) - (dividend._real * divisor._imag)) / modSquared); } @@ -942,7 +967,6 @@ namespace MathNet.Numerics #if !SILVERLIGHT [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] #endif - public Complex32 Plus() { return this; @@ -957,7 +981,6 @@ namespace MathNet.Numerics #if !SILVERLIGHT [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] #endif - public Complex32 Negate() { return -this; @@ -975,7 +998,6 @@ namespace MathNet.Numerics #if !SILVERLIGHT [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] #endif - public Complex32 Add(Complex32 other) { return this + other; @@ -993,7 +1015,6 @@ namespace MathNet.Numerics #if !SILVERLIGHT [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] #endif - public Complex32 Subtract(Complex32 other) { return this - other; @@ -1011,7 +1032,6 @@ namespace MathNet.Numerics #if !SILVERLIGHT [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] #endif - public Complex32 Multiply(Complex32 multiplier) { return this * multiplier; @@ -1029,7 +1049,6 @@ namespace MathNet.Numerics #if !SILVERLIGHT [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] #endif - public Complex32 Divide(Complex32 divisor) { return this / divisor; @@ -1048,7 +1067,7 @@ namespace MathNet.Numerics /// double IPrecisionSupport.Norm() { - return MagnitudeSquared; + return this.MagnitudeSquared; } /// @@ -1131,8 +1150,8 @@ namespace MathNet.Numerics var keywords = new[] { - textInfo.ListSeparator, numberFormatInfo.NaNSymbol, - numberFormatInfo.NegativeInfinitySymbol, numberFormatInfo.PositiveInfinitySymbol, + textInfo.ListSeparator, numberFormatInfo.NaNSymbol, + numberFormatInfo.NegativeInfinitySymbol, numberFormatInfo.PositiveInfinitySymbol, "+", "-", "i", "j" }; @@ -1212,7 +1231,7 @@ namespace MathNet.Numerics } } - bool negative = false; + var negative = false; if (token.Value == "-") { negative = true; @@ -1321,6 +1340,7 @@ namespace MathNet.Numerics #endregion #region Conversion + /// /// Explicit conversion of a real decimal to a Complex32. /// @@ -1444,7 +1464,7 @@ namespace MathNet.Numerics { return new Complex32(value, 0.0f); } - + /// /// Implicit conversion of a real double to a Complex32. /// @@ -1455,6 +1475,10 @@ namespace MathNet.Numerics return new Complex32((float)value, 0.0f); } + /// + /// Converts this Complex32 to a . + /// + /// A with the same values as this Complex32. public Complex ToComplex() { return new Complex(this._real, this._imag); diff --git a/src/Numerics/ComplexExtensions.cs b/src/Numerics/ComplexExtensions.cs index 16d5aff5..0038b6f3 100644 --- a/src/Numerics/ComplexExtensions.cs +++ b/src/Numerics/ComplexExtensions.cs @@ -1,9 +1,7 @@ // // Math.NET Numerics, part of the Math.NET Project // http://mathnet.opensourcedotnet.info -// // Copyright (c) 2009-2010 Math.NET -// // Permission is hereby granted, free of charge, to any person // obtaining a copy of this software and associated documentation // files (the "Software"), to deal in the Software without @@ -12,10 +10,8 @@ // copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following // conditions: -// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -40,63 +36,69 @@ namespace MathNet.Numerics /// /// Gets a value indicating whether the Complex32 is zero. /// - /// true if this instance is zero; otherwise, false. + /// The number to perfom this operation on. + /// true if this instance is zero; otherwise, false. public static bool IsZero(this Complex complex) { - return complex.Real == 0.0 && complex.Imaginary == 0.0; + return complex.Real == 0.0 && complex.Imaginary == 0.0; } /// /// Gets a value indicating whether the Complex32 is one. /// - /// true if this instance is one; otherwise, false. + /// The number to perfom this operation on. + /// true if this instance is one; otherwise, false. public static bool IsOne(this Complex complex) { - return complex.Real == 1.0 && complex.Imaginary == 0.0; + return complex.Real == 1.0 && complex.Imaginary == 0.0; } /// /// Gets a value indicating whether the Complex32 is the imaginary unit. /// - /// true if this instance is ImaginaryOne; otherwise, false. + /// true if this instance is ImaginaryOne; otherwise, false. + /// The number to perfom this operation on. public static bool IsImaginaryOne(this Complex complex) { - return complex.Real == 0.0 && complex.Imaginary == 1.0; + return complex.Real == 0.0 && complex.Imaginary == 1.0; } /// /// Gets a value indicating whether the provided Complex32evaluates /// to a value that is not a number. /// - /// - /// true if this instance is ; otherwise, + /// The number to perfom this operation on. + /// + /// true if this instance is NaN; otherwise, /// false. - /// + /// public static bool IsNaN(this Complex complex) { - return double.IsNaN(complex.Real) || double.IsNaN(complex.Imaginary); + return double.IsNaN(complex.Real) || double.IsNaN(complex.Imaginary); } /// /// Gets a value indicating whether the provided Complex32 evaluates to an /// infinite value. /// - /// + /// The number to perfom this operation on. + /// /// true if this instance is infinite; otherwise, false. - /// + /// /// /// True if it either evaluates to a complex infinity /// or to a directed infinity. /// public static bool IsInfinity(this Complex complex) { - return double.IsInfinity(complex.Real) || double.IsInfinity(complex.Imaginary); + return double.IsInfinity(complex.Real) || double.IsInfinity(complex.Imaginary); } /// /// Gets a value indicating whether the provided Complex32 is real. /// - /// true if this instance is a real number; otherwise, false. + /// The number to perfom this operation on. + /// true if this instance is a real number; otherwise, false. public static bool IsReal(this Complex complex) { return complex.Imaginary == 0.0; @@ -105,17 +107,19 @@ namespace MathNet.Numerics /// /// Gets a value indicating whether the provided Complex32 is real and not negative, that is >= 0. /// - /// + /// The number to perfom this operation on. + /// /// true if this instance is real nonnegative number; otherwise, false. - /// + /// public static bool IsRealNonNegative(this Complex complex) { - return complex.Imaginary == 0.0f && complex.Real >= 0; + return complex.Imaginary == 0.0f && complex.Real >= 0; } /// - /// Gets the conjugate of this Complex32. + /// Gets the conjugate of the Complex number. /// + /// The number to perfom this operation on. /// /// The semantic of setting the conjugate is such that /// @@ -128,22 +132,26 @@ namespace MathNet.Numerics /// a = b.Conjugate /// /// + /// The conjugate of the number. public static Complex Conjugate(this Complex complex) { - return new Complex(complex.Real, -complex.Imaginary); + return new Complex(complex.Real, -complex.Imaginary); } /// - /// Gets the squared magnitude of this Complex. + /// Gets the squared magnitude of the Complex number. /// + /// The number to perfom this operation on. + /// The squared magnitude of the Complex number. public static double MagnitudeSquared(this Complex complex) { - return (complex.Real * complex.Real) + (complex.Imaginary * complex.Imaginary); + return (complex.Real * complex.Real) + (complex.Imaginary * complex.Imaginary); } /// /// Exponential of this Complex (exp(x), E^x). /// + /// The number to perfom this operation on. /// /// The exponential of this complex number. /// @@ -161,6 +169,7 @@ namespace MathNet.Numerics /// /// Natural Logarithm of this Complex (Base E). /// + /// The number to perfom this operation on. /// /// The natural logarithm of this complex number. /// @@ -177,6 +186,7 @@ namespace MathNet.Numerics /// /// Raise this Complex to the given value. /// + /// The number to perfom this operation on. /// /// The exponent. /// @@ -216,6 +226,7 @@ namespace MathNet.Numerics /// /// Raise this Complex to the inverse of the given value. /// + /// The number to perfom this operation on. /// /// The root exponent. /// @@ -230,6 +241,7 @@ namespace MathNet.Numerics /// /// The Square (power 2) of this Complex /// + /// The number to perfom this operation on. /// /// The square of this complex number. /// @@ -246,6 +258,7 @@ namespace MathNet.Numerics /// /// The Square Root (power 1/2) of this Complex /// + /// The number to perfom this operation on. /// /// The square root of this complex number. /// @@ -292,6 +305,7 @@ namespace MathNet.Numerics /// Returns a Norm of a value of this type, which is appropriate for measuring how /// close this value is to zero. /// + /// The number to perfom this operation on. /// A norm of this value. public static double Norm(this Complex complex) { @@ -302,11 +316,12 @@ namespace MathNet.Numerics /// Returns a Norm of the difference of two values of this type, which is /// appropriate for measuring how close together these two values are. /// + /// The number to perfom this operation on. /// The value to compare with. /// A norm of the difference between this and the other value. public static double NormOfDifference(this Complex complex, Complex otherValue) { - return (complex- otherValue).MagnitudeSquared(); + return (complex - otherValue).MagnitudeSquared(); } /// @@ -370,8 +385,8 @@ namespace MathNet.Numerics var keywords = new[] { - textInfo.ListSeparator, numberFormatInfo.NaNSymbol, - numberFormatInfo.NegativeInfinitySymbol, numberFormatInfo.PositiveInfinitySymbol, + textInfo.ListSeparator, numberFormatInfo.NaNSymbol, + numberFormatInfo.NegativeInfinitySymbol, numberFormatInfo.PositiveInfinitySymbol, "+", "-", "i", "j" }; @@ -382,7 +397,7 @@ namespace MathNet.Numerics // parse the left part bool isLeftPartImaginary; - double leftPart = ParsePart(ref token, out isLeftPartImaginary, formatProvider); + var leftPart = ParsePart(ref token, out isLeftPartImaginary, formatProvider); if (token == null) { return isLeftPartImaginary ? new Complex(0, leftPart) : new Complex(leftPart, 0); @@ -401,7 +416,7 @@ namespace MathNet.Numerics } bool isRightPartImaginary; - double rightPart = ParsePart(ref token, out isRightPartImaginary, formatProvider); + var rightPart = ParsePart(ref token, out isRightPartImaginary, formatProvider); return new Complex(leftPart, rightPart); } @@ -409,7 +424,7 @@ namespace MathNet.Numerics { // format: real + imag bool isRightPartImaginary; - double rightPart = ParsePart(ref token, out isRightPartImaginary, formatProvider); + var rightPart = ParsePart(ref token, out isRightPartImaginary, formatProvider); if (!(isLeftPartImaginary ^ isRightPartImaginary)) { @@ -451,7 +466,7 @@ namespace MathNet.Numerics } } - bool negative = false; + var negative = false; if (token.Value == "-") { negative = true; @@ -511,7 +526,7 @@ namespace MathNet.Numerics /// /// /// If the conversion succeeds, the result will contain a complex number equivalent to value. - /// Otherwise the result will contain complex32.Zero. This parameter is passed uninitialized + /// Otherwise the result will contain Complex.Zero. This parameter is passed uninitialized. /// public static bool TryToComplex(this string value, out Complex result) { @@ -557,24 +572,81 @@ namespace MathNet.Numerics return ret; } + /// + /// Creates a Complex32 number based on a string. The string can be in the + /// following formats (without the quotes): 'n', 'ni', 'n +/- ni', + /// 'ni +/- n', 'n,n', 'n,ni,' '(n,n)', or '(n,ni)', where n is a double. + /// + /// + /// A complex number containing the value specified by the given string. + /// + /// + /// the string to parse. + /// public static Complex32 ToComplex32(this string value) { return Complex32.Parse(value); } + /// + /// Creates a Complex32 number based on a string. The string can be in the + /// following formats (without the quotes): 'n', 'ni', 'n +/- ni', + /// 'ni +/- n', 'n,n', 'n,ni,' '(n,n)', or '(n,ni)', where n is a double. + /// + /// + /// A complex number containing the value specified by the given string. + /// + /// + /// the string to parse. + /// + /// + /// An that supplies culture-specific + /// formatting information. + /// public static Complex32 ToComplex32(this string value, IFormatProvider formatProvider) { return Complex32.Parse(value, formatProvider); } + /// + /// Converts the string representation of a complex number to a single-precision complex number equivalent. + /// A return value indicates whether the conversion succeeded or failed. + /// + /// + /// A string containing a complex number to convert. + /// + /// + /// The parsed value. + /// + /// + /// If the conversion succeeds, the result will contain a complex number equivalent to value. + /// Otherwise the result will contain complex32.Zero. This parameter is passed uninitialized. + /// public static bool TryToComplex32(this string value, out Complex32 result) { return Complex32.TryParse(value, out result); } + /// + /// Converts the string representation of a complex number to single-precision complex number equivalent. + /// A return value indicates whether the conversion succeeded or failed. + /// + /// + /// A string containing a complex number to convert. + /// + /// + /// An that supplies culture-specific formatting information about value. + /// + /// + /// The parsed value. + /// + /// + /// If the conversion succeeds, the result will contain a complex number equivalent to value. + /// Otherwise the result will contain Complex.Zero. This parameter is passed uninitialized. + /// public static bool TryToComplex32(this string value, IFormatProvider formatProvider, out Complex32 result) { return Complex32.TryParse(value, formatProvider, out result); } } -} +} \ No newline at end of file