Exemplo n.º 1
0
        public static ComplexD Log(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if ((a.Real > 0.0) && (a.Imaginary == 0.0))
            {
                result.Real      = System.Math.Log(a.Real);
                result.Imaginary = 0.0;
            }
            else if (a.Real == 0.0)
            {
                if (a.Imaginary > 0.0)
                {
                    result.Real      = System.Math.Log(a.Imaginary);
                    result.Imaginary = MathFunctions.HalfPI;
                }
                else
                {
                    result.Real      = System.Math.Log(-(a.Imaginary));
                    result.Imaginary = -MathFunctions.HalfPI;
                }
            }
            else
            {
                result.Real      = System.Math.Log(a.GetModulus());
                result.Imaginary = System.Math.Atan2(a.Imaginary, a.Real);
            }

            return(result);
        }
Exemplo n.º 2
0
        public static ComplexD Sqrt(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if ((a.Real == 0.0) && (a.Imaginary == 0.0))
            {
                return(result);
            }
            else if (a.Imaginary == 0.0)
            {
                result.Real      = (a.Real > 0) ? System.Math.Sqrt(a.Real) : System.Math.Sqrt(-a.Real);
                result.Imaginary = 0.0;
            }
            else
            {
                double modulus = a.GetModulus();

                result.Real      = System.Math.Sqrt(0.5 * (modulus + a.Real));
                result.Imaginary = System.Math.Sqrt(0.5 * (modulus - a.Real));
                if (a.Imaginary < 0.0)
                {
                    result.Imaginary = -result.Imaginary;
                }
            }

            return(result);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Tests whether two complex numbers are approximately equal given a tolerance value.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <param name="tolerance">The tolerance value used to test approximate equality.</param>
 /// <returns><see langword="true"/> if the two vectors are approximately equal; otherwise, <see langword="false"/>.</returns>
 public static bool ApproxEqual(ComplexD a, ComplexD b, double tolerance)
 {
     return
         (
         (System.Math.Abs(a.Real - b.Real) <= tolerance) &&
         (System.Math.Abs(a.Imaginary - b.Imaginary) <= tolerance)
         );
 }
Exemplo n.º 4
0
        /// <summary>
        /// Multiplies two complex numbers.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="b">A <see cref="ComplexD"/> instance.</param>
        /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
        public static ComplexD Multiply(ComplexD a, ComplexD b)
        {
            // (x + yi)(u + vi) = (xu – yv) + (xv + yu)i.
            double x = a.Real, y = a.Imaginary;
            double u = b.Real, v = b.Imaginary;

            return(new ComplexD(x * u - y * v, x * v + y * u));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Returns a value indicating whether this instance is equal to
 /// the specified object.
 /// </summary>
 /// <param name="obj">An object to compare to this instance.</param>
 /// <returns><see langword="true"/> if <paramref name="obj"/> is a <see cref="ComplexD"/> and has the same values as this instance; otherwise, <see langword="false"/>.</returns>
 public override bool Equals(object obj)
 {
     if (obj is ComplexD)
     {
         ComplexD c = (ComplexD)obj;
         return((this.Real == c.Real) && (this.Imaginary == c.Imaginary));
     }
     return(false);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Multiplies two complex numbers and put the result in a third complex number.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="b">A <see cref="ComplexD"/> instance.</param>
        /// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
        public static void Multiply(ComplexD a, ComplexD b, ref ComplexD result)
        {
            // (x + yi)(u + vi) = (xu – yv) + (xv + yu)i.
            double x = a.Real, y = a.Imaginary;
            double u = b.Real, v = b.Imaginary;

            result.Real      = x * u - y * v;
            result.Imaginary = x * v + y * u;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">The <see cref="System.Globalization.CultureInfo"/> to use as the current culture. </param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <returns>An <see cref="Object"/> that represents the converted value.</returns>
        /// <exception cref="ParseException">Failed parsing from string.</exception>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value.GetType() == typeof(string))
            {
                return(ComplexD.Parse((string)value));
            }

            return(base.ConvertFrom(context, culture, value));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Divides a scalar by a complex and put the result into another complex number.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="s">A scalar.</param>
        /// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
        public static void Divide(double s, ComplexD a, ref ComplexD result)
        {
            if ((a.Real == 0) || (a.Imaginary == 0))
            {
                throw new DivideByZeroException();
            }

            result.Real      = s / a.Real;
            result.Imaginary = s / a.Imaginary;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Divides a complex by a scalar and put the result into another complex number.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="s">A scalar.</param>
        /// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
        public static void Divide(ComplexD a, double s, ref ComplexD result)
        {
            if (s == 0)
            {
                throw new DivideByZeroException();
            }

            result.Real      = a.Real / s;
            result.Imaginary = a.Imaginary / s;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Divides a scalar by a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD Divide(double s, ComplexD a)
 {
     if ((a.Real == 0) || (a.Imaginary == 0))
     {
         throw new DivideByZeroException();
     }
     return(new ComplexD(
                s / a.Real,
                s / a.Imaginary));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Divides a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD Divide(ComplexD a, double s)
 {
     if (s == 0)
     {
         throw new DivideByZeroException();
     }
     return(new ComplexD(
                a.Real / s,
                a.Imaginary / s));
 }
Exemplo n.º 12
0
        /// <summary>
        /// Converts the given value object to the specified type, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">A <see cref="System.Globalization.CultureInfo"/> object. If a null reference (Nothing in Visual Basic) is passed, the current culture is assumed.</param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <param name="destinationType">The Type to convert the <paramref name="value"/> parameter to.</param>
        /// <returns>An <see cref="Object"/> that represents the converted value.</returns>
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if ((destinationType == typeof(string)) && (value is ComplexD))
            {
                ComplexD c = (ComplexD)value;
                return(c.ToString());
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Exemplo n.º 13
0
        public static ComplexD Exp(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;
            double   r      = System.Math.Exp(a.Real);

            result.Real      = r * System.Math.Cos(a.Imaginary);
            result.Imaginary = r * System.Math.Sin(a.Imaginary);

            return(result);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Divides a complex by a complex and put the result in a third complex number.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="b">A <see cref="ComplexD"/> instance.</param>
        /// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
        public static void Divide(ComplexD a, ComplexD b, ref ComplexD result)
        {
            double x = a.Real, y = a.Imaginary;
            double u = b.Real, v = b.Imaginary;
            double modulusSquared = u * u + v * v;

            if (modulusSquared == 0)
            {
                throw new DivideByZeroException();
            }

            double invModulusSquared = 1 / modulusSquared;

            result.Real      = (x * u + y * v) * invModulusSquared;
            result.Imaginary = (y * u - x * v) * invModulusSquared;
        }
Exemplo n.º 15
0
        public static ComplexD Cos(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if (a.Imaginary == 0.0)
            {
                result.Real      = System.Math.Cos(a.Real);
                result.Imaginary = 0.0;
            }
            else
            {
                result.Real      = System.Math.Cos(a.Real) * System.Math.Cosh(a.Imaginary);
                result.Imaginary = -System.Math.Sin(a.Real) * System.Math.Sinh(a.Imaginary);
            }

            return(result);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Divides a complex by a complex.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="b">A <see cref="ComplexD"/> instance.</param>
        /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
        public static ComplexD Divide(ComplexD a, ComplexD b)
        {
            double x = a.Real, y = a.Imaginary;
            double u = b.Real, v = b.Imaginary;
            double modulusSquared = u * u + v * v;

            if (modulusSquared == 0)
            {
                throw new DivideByZeroException();
            }

            double invModulusSquared = 1 / modulusSquared;

            return(new ComplexD(
                       (x * u + y * v) * invModulusSquared,
                       (y * u - x * v) * invModulusSquared));
        }
Exemplo n.º 17
0
        public static ComplexD Tan(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if (a.Imaginary == 0.0)
            {
                result.Real      = System.Math.Tan(a.Real);
                result.Imaginary = 0.0;
            }
            else
            {
                double real2 = 2 * a.Real;
                double imag2 = 2 * a.Imaginary;
                double denom = System.Math.Cos(real2) + System.Math.Cosh(real2);

                result.Real      = System.Math.Sin(real2) / denom;
                result.Imaginary = System.Math.Sinh(imag2) / denom;
            }

            return(result);
        }
 public override void Remove(ComplexD value)
 {
     this._collection.Remove(value);
 }
 public override int IndexOf(ComplexD value)
 {
     return this._collection.IndexOf(value);
 }
 public override void CopyTo(ComplexD[] array)
 {
     this._collection.CopyTo(array);
 }
            public override void AddRange(ComplexD[] array)
            {
                foreach (ComplexD value in array)
                    CheckUnique(value);

                this._collection.AddRange(array);
            }
 public override void Remove(ComplexD value)
 {
     lock (this._root) this._collection.Remove(value);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComplexD"/> class using values from a given complex instance.
 /// </summary>
 /// <param name="c">A complex number to get values from.</param>
 public ComplexD(ComplexD c)
 {
     _real  = c.Real;
     _image = c.Imaginary;
 }
 /// <summary>
 /// Searches the entire sorted <see cref="ComplexDArrayList"/> for an
 /// <see cref="ComplexD"/> element using the default comparer
 /// and returns the zero-based index of the element.
 /// </summary>
 /// <param name="value">The <see cref="ComplexD"/> object
 /// to locate in the <see cref="ComplexDArrayList"/>.
 /// </param>
 /// <returns>The zero-based index of <paramref name="value"/> in the sorted
 /// <see cref="ComplexDArrayList"/>, if <paramref name="value"/> is found;
 /// otherwise, a negative number, which is the bitwise complement of the index
 /// of the next element that is larger than <paramref name="value"/> or, if there
 /// is no larger element, the bitwise complement of <see cref="Count"/>.</returns>
 /// <exception cref="InvalidOperationException">
 /// Neither <paramref name="value"/> nor the elements of the <see cref="ComplexDArrayList"/>
 /// implement the <see cref="IComparable"/> interface.</exception>
 /// <remarks>Please refer to <see cref="ArrayList.BinarySearch"/> for details.</remarks>
 public virtual int BinarySearch(ComplexD value)
 {
     return Array.BinarySearch(this._array, 0, this._count, value);
 }
 public override void Insert(int index, ComplexD value)
 {
     throw new NotSupportedException(
         "Read-only collections cannot be modified.");
 }
Exemplo n.º 26
0
 /// <summary>
 /// Subtracts a complex from a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the difference.</returns>
 public static ComplexD operator-(double s, ComplexD a)
 {
     return(ComplexD.Subtract(s, a));
 }
Exemplo n.º 27
0
 /// <summary>
 /// Subtracts a scalar from a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the difference.</returns>
 public static ComplexD operator-(ComplexD a, double s)
 {
     return(ComplexD.Subtract(a, s));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Subtracts a complex from a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the difference.</returns>
 public static ComplexD operator-(ComplexD a, ComplexD b)
 {
     return(ComplexD.Subtract(a, b));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Adds a complex number and a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the sum.</returns>
 public static ComplexD operator+(double s, ComplexD a)
 {
     return(ComplexD.Add(a, s));
 }
Exemplo n.º 30
0
 /// <summary>
 /// Adds two complex numbers.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the sum.</returns>
 public static ComplexD operator+(ComplexD a, ComplexD b)
 {
     return(ComplexD.Add(a, b));
 }
Exemplo n.º 31
0
 /// <summary>
 /// Negates the complex number.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the negated values.</returns>
 public static ComplexD operator-(ComplexD a)
 {
     return(ComplexD.Negate(a));
 }
 private void CheckUnique(int index, ComplexD value)
 {
     int existing = IndexOf(value);
     if (existing >= 0 && existing != index)
         throw new NotSupportedException(
             "Unique collections cannot contain duplicate elements.");
 }
        /// <summary>
        /// Adds a <see cref="ComplexD"/> to the end of the <see cref="ComplexDArrayList"/>.
        /// </summary>
        /// <param name="value">The <see cref="ComplexD"/> object
        /// to be added to the end of the <see cref="ComplexDArrayList"/>.
        /// </param>
        /// <returns>The <see cref="ComplexDArrayList"/> index at which the
        /// <paramref name="value"/> has been added.</returns>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="ComplexDArrayList"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b>ComplexDArrayList</b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b>ComplexDArrayList</b> already contains the specified
        /// <paramref name="value"/>, and the <b>ComplexDArrayList</b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Add"/> for details.</remarks>
        public virtual int Add(ComplexD value)
        {
            if (this._count == this._array.Length)
                EnsureCapacity(this._count + 1);

            ++this._version;
            this._array[this._count] = value;
            return this._count++;
        }
 public override int Add(ComplexD value)
 {
     lock (this._root) return this._collection.Add(value);
 }
Exemplo n.º 35
0
 /// <summary>
 /// Multiplies two complex numbers.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator*(ComplexD a, ComplexD b)
 {
     return(ComplexD.Multiply(a, b));
 }
 public override void CopyTo(ComplexD[] array)
 {
     lock (this._root) this._collection.CopyTo(array);
 }
 public override void Remove(ComplexD value)
 {
     throw new NotSupportedException(
         "Read-only collections cannot be modified.");
 }
Exemplo n.º 38
0
 /// <summary>
 /// Multiplies a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator*(ComplexD a, double s)
 {
     return(ComplexD.Multiply(a, s));
 }
 public override void AddRange(ComplexD[] array)
 {
     lock (this._root) this._collection.AddRange(array);
 }
Exemplo n.º 40
0
 /// <summary>
 /// Divides a complex by a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator/(ComplexD a, ComplexD b)
 {
     return(ComplexD.Divide(a, b));
 }
 public override void Insert(int index, ComplexD value)
 {
     lock (this._root) this._collection.Insert(index, value);
 }
Exemplo n.º 42
0
 /// <summary>
 /// Divides a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator/(ComplexD a, double s)
 {
     return(ComplexD.Divide(a, s));
 }
 public override int Add(ComplexD value)
 {
     CheckUnique(value);
     return this._collection.Add(value);
 }
Exemplo n.º 44
0
 /// <summary>
 /// Divides a scalar by a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator/(double s, ComplexD a)
 {
     return(ComplexD.Divide(s, a));
 }
 public override int BinarySearch(ComplexD value)
 {
     return this._collection.BinarySearch(value);
 }
 /// <overloads>
 /// Copies the <see cref="ComplexDArrayList"/> or a portion of it to a one-dimensional array.
 /// </overloads>
 /// <summary>
 /// Copies the entire <see cref="ComplexDArrayList"/> to a one-dimensional <see cref="Array"/>
 /// of <see cref="ComplexD"/> elements, starting at the beginning of the target array.
 /// </summary>
 /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the
 /// <see cref="ComplexD"/> elements copied from the <see cref="ComplexDArrayList"/>.
 /// The <b>Array</b> must have zero-based indexing.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="array"/> is a null reference.</exception>
 /// <exception cref="ArgumentException">
 /// The number of elements in the source <see cref="ComplexDArrayList"/> is greater
 /// than the available space in the destination <paramref name="array"/>.</exception>
 /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks>
 public virtual void CopyTo(ComplexD[] array)
 {
     CheckTargetArray(array, 0);
     Array.Copy(this._array, array, this._count);
 }
 public override void CopyTo(ComplexD[] array, int arrayIndex)
 {
     this._collection.CopyTo(array, arrayIndex);
 }
 /// <summary>
 /// Returns the zero-based index of the first occurrence of the specified
 /// <see cref="ComplexD"/> in the <see cref="ComplexDArrayList"/>.
 /// </summary>
 /// <param name="value">The <see cref="ComplexD"/> object
 /// to locate in the <see cref="ComplexDArrayList"/>.
 /// </param>
 /// <returns>
 /// The zero-based index of the first occurrence of <paramref name="value"/>
 /// in the <see cref="ComplexDArrayList"/>, if found; otherwise, -1.
 /// </returns>
 /// <remarks>Please refer to <see cref="ArrayList.IndexOf"/> for details.</remarks>
 public virtual int IndexOf(ComplexD value)
 {
     return Array.IndexOf(this._array, value, 0, this._count);
 }
 public override void Insert(int index, ComplexD value)
 {
     CheckUnique(value);
     this._collection.Insert(index, value);
 }
        /// <summary>
        /// Inserts a <see cref="ComplexD"/> element into the
        /// <see cref="ComplexDArrayList"/> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="value"/>
        /// should be inserted.</param>
        /// <param name="value">The <see cref="ComplexD"/> object
        /// to insert into the <see cref="ComplexDArrayList"/>.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="index"/> is greater than <see cref="Count"/>.</para>
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="ComplexDArrayList"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b>ComplexDArrayList</b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b>ComplexDArrayList</b> already contains the specified
        /// <paramref name="value"/>, and the <b>ComplexDArrayList</b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Insert"/> for details.</remarks>
        public virtual void Insert(int index, ComplexD value)
        {
            if (index < 0)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument cannot be negative.");

            if (index > this._count)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument cannot exceed Count.");

            if (this._count == this._array.Length)
                EnsureCapacity(this._count + 1);

            ++this._version;
            if (index < this._count)
                Array.Copy(this._array, index,
                    this._array, index + 1, this._count - index);

            this._array[index] = value;
            ++this._count;
        }
 private void CheckUnique(ComplexD value)
 {
     if (IndexOf(value) >= 0)
         throw new NotSupportedException(
             "Unique collections cannot contain duplicate elements.");
 }
 /// <summary>
 /// Removes the first occurrence of the specified <see cref="ComplexD"/>
 /// from the <see cref="ComplexDArrayList"/>.
 /// </summary>
 /// <param name="value">The <see cref="ComplexD"/> object
 /// to remove from the <see cref="ComplexDArrayList"/>.
 /// </param>
 /// <exception cref="NotSupportedException">
 /// <para>The <see cref="ComplexDArrayList"/> is read-only.</para>
 /// <para>-or-</para>
 /// <para>The <b>ComplexDArrayList</b> has a fixed size.</para></exception>
 /// <remarks>Please refer to <see cref="ArrayList.Remove"/> for details.</remarks>
 public virtual void Remove(ComplexD value)
 {
     int index = IndexOf(value);
     if (index >= 0) RemoveAt(index);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComplexDArrayList"/> class
        /// that contains elements copied from the specified <see cref="ComplexD"/>
        /// array and that has the same initial capacity as the number of elements copied.
        /// </summary>
        /// <param name="array">An <see cref="Array"/> of <see cref="ComplexD"/>
        /// elements that are copied to the new collection.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="array"/> is a null reference.</exception>
        /// <remarks>Please refer to <see cref="ArrayList(ICollection)"/> for details.</remarks>
        public ComplexDArrayList(ComplexD[] array)
        {
            if (array == null)
                throw new ArgumentNullException("array");

            this._array = new ComplexD[array.Length];
            AddRange(array);
        }
 /// <summary>
 /// Copies the elements of the <see cref="ComplexDArrayList"/> to a new
 /// <see cref="Array"/> of <see cref="ComplexD"/> elements.
 /// </summary>
 /// <returns>A one-dimensional <see cref="Array"/> of <see cref="ComplexD"/>
 /// elements containing copies of the elements of the <see cref="ComplexDArrayList"/>.</returns>
 /// <remarks>Please refer to <see cref="ArrayList.ToArray"/> for details.</remarks>
 public virtual ComplexD[] ToArray()
 {
     ComplexD[] array = new ComplexD[this._count];
     Array.Copy(this._array, array, this._count);
     return array;
 }
        /// <summary>
        /// Adds the elements of a <see cref="ComplexD"/> array
        /// to the end of the <see cref="ComplexDArrayList"/>.
        /// </summary>
        /// <param name="array">An <see cref="Array"/> of <see cref="ComplexD"/> elements
        /// that should be added to the end of the <see cref="ComplexDArrayList"/>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="array"/> is a null reference.</exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="ComplexDArrayList"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b>ComplexDArrayList</b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b>ComplexDArrayList</b> already contains one or more elements
        /// in the specified <paramref name="array"/>, and the <b>ComplexDArrayList</b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.AddRange"/> for details.</remarks>
        public virtual void AddRange(ComplexD[] array)
        {
            if (array == null)
                throw new ArgumentNullException("array");

            if (array.Length == 0) return;
            if (this._count + array.Length > this._array.Length)
                EnsureCapacity(this._count + array.Length);

            ++this._version;
            Array.Copy(array, 0, this._array, this._count, array.Length);
            this._count += array.Length;
        }
 public override void AddRange(ComplexD[] array)
 {
     throw new NotSupportedException(
         "Read-only collections cannot be modified.");
 }
 /// <summary>
 /// Determines whether the <see cref="ComplexDArrayList"/>
 /// contains the specified <see cref="ComplexD"/> element.
 /// </summary>
 /// <param name="value">The <see cref="ComplexD"/> object
 /// to locate in the <see cref="ComplexDArrayList"/>.
 /// </param>
 /// <returns><c>true</c> if <paramref name="value"/> is found in the
 /// <see cref="ComplexDArrayList"/>; otherwise, <c>false</c>.</returns>
 /// <remarks>Please refer to <see cref="ArrayList.Contains"/> for details.</remarks>
 public bool Contains(ComplexD value)
 {
     return (IndexOf(value) >= 0);
 }
Exemplo n.º 58
0
 /// <summary>
 /// Tests whether two complex numbers are approximately equal using default tolerance value.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns><see langword="true"/> if the two vectors are approximately equal; otherwise, <see langword="false"/>.</returns>
 public static bool ApproxEqual(ComplexD a, ComplexD b)
 {
     return(ApproxEqual(a, b, MathFunctions.EpsilonD));
 }
 /// <summary>
 /// Copies the entire <see cref="ComplexDArrayList"/> to a one-dimensional <see cref="Array"/>
 /// of <see cref="ComplexD"/> elements, starting at the specified index of the target array.
 /// </summary>
 /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the
 /// <see cref="ComplexD"/> elements copied from the <see cref="ComplexDArrayList"/>.
 /// The <b>Array</b> must have zero-based indexing.</param>
 /// <param name="arrayIndex">The zero-based index in <paramref name="array"/>
 /// at which copying begins.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="array"/> is a null reference.</exception>
 /// <exception cref="ArgumentOutOfRangeException">
 /// <paramref name="arrayIndex"/> is less than zero.</exception>
 /// <exception cref="ArgumentException"><para>
 /// <paramref name="arrayIndex"/> is equal to or greater than the length of <paramref name="array"/>.
 /// </para><para>-or-</para><para>
 /// The number of elements in the source <see cref="ComplexDArrayList"/> is greater than the
 /// available space from <paramref name="arrayIndex"/> to the end of the destination
 /// <paramref name="array"/>.</para></exception>
 /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks>
 public virtual void CopyTo(ComplexD[] array, int arrayIndex)
 {
     CheckTargetArray(array, arrayIndex);
     Array.Copy(this._array, 0, array, arrayIndex, this._count);
 }
Exemplo n.º 60
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComplexD"/> class using values from a given complex instance.
 /// </summary>
 /// <param name="c">A complex number to get values from.</param>
 public ComplexD(ComplexD c)
 {
     _real = c.Real;
     _image = c.Imaginary;
 }