예제 #1
0
        /// <summary>
        /// Converts the string representation of a number to its <typeparamref name="T"/> equivalent. A return value indicates whether the conversion succeeded or failed.
        /// </summary>
        /// <param name="value">The number string representation</param>
        /// <param name="provider">An object that supplies culture-specific formatting information</param>
        /// <param name="result">Result of conversion</param>
        /// <returns>true if conversion successed; otherwise, false</returns>
        public override bool TryParse(string value, IFormatProvider provider, out Complex result)
        {
            string[] values = value.Split(';');
            if (values.Length != 2)
            {
                throw new Exception(string.Format("Cannot parse value {0}", value));
            }
            double real, imaginary;

            result = new Block2x2();
            bool returnValue = double.TryParse(values[0], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent, provider, out real);

            returnValue &= double.TryParse(values[0], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent, provider, out imaginary);
            if (!returnValue)
            {
                result = default(Complex);
            }
            else
            {
                result = new Complex(real, imaginary);
            }
            return(returnValue);
        }
예제 #2
0
        unsafe internal static void Multiply(Block2x2 *value1, Block2x2 value2, Block2x2 *result, int length, int value1Index = 0, int value2Index = 0, int resultIndex = 0)
        {
            double  f00       = value2.f00;
            double  f01       = value2.f01;
            double  f10       = value2.f10;
            double  f11       = value2.f11;
            double *ptrValue1 = (double *)(value1 + value1Index);
            double *ptrResult = (double *)(result + resultIndex);
            double *ptrEnd    = (double *)(result + length) - 31;

            // Main loop, pointers for row values
            while (ptrResult < ptrEnd)
            {
                *ptrResult = *ptrValue1 * f00 + ptrValue1[1] * f10;
                ptrResult[1]  = *ptrValue1 * f01 + ptrValue1[1] * f11;
                ptrResult[2]  = ptrValue1[2] * f00 + ptrValue1[3] * f10;
                ptrResult[3]  = ptrValue1[2] * f01 + ptrValue1[3] * f11;
                ptrResult[4]  = ptrValue1[4] * f00 + ptrValue1[5] * f10;
                ptrResult[5]  = ptrValue1[4] * f01 + ptrValue1[5] * f11;
                ptrResult[6]  = ptrValue1[6] * f00 + ptrValue1[7] * f10;
                ptrResult[7]  = ptrValue1[6] * f01 + ptrValue1[7] * f11;
                ptrResult[8]  = ptrValue1[8] * f00 + ptrValue1[9] * f10;
                ptrResult[9]  = ptrValue1[8] * f01 + ptrValue1[9] * f11;
                ptrResult[10] = ptrValue1[10] * f00 + ptrValue1[11] * f10;
                ptrResult[11] = ptrValue1[10] * f01 + ptrValue1[11] * f11;
                ptrResult[12] = ptrValue1[12] * f00 + ptrValue1[13] * f10;
                ptrResult[13] = ptrValue1[12] * f01 + ptrValue1[13] * f11;
                ptrResult[14] = ptrValue1[14] * f00 + ptrValue1[15] * f10;
                ptrResult[15] = ptrValue1[14] * f01 + ptrValue1[15] * f11;
                ptrResult[16] = ptrValue1[16] * f00 + ptrValue1[17] * f10;
                ptrResult[17] = ptrValue1[16] * f01 + ptrValue1[17] * f11;
                ptrResult[18] = ptrValue1[18] * f00 + ptrValue1[19] * f10;
                ptrResult[19] = ptrValue1[18] * f01 + ptrValue1[19] * f11;
                ptrResult[20] = ptrValue1[20] * f00 + ptrValue1[21] * f10;
                ptrResult[21] = ptrValue1[20] * f01 + ptrValue1[21] * f11;
                ptrResult[22] = ptrValue1[22] * f00 + ptrValue1[23] * f10;
                ptrResult[23] = ptrValue1[22] * f01 + ptrValue1[23] * f11;
                ptrResult[24] = ptrValue1[24] * f00 + ptrValue1[25] * f10;
                ptrResult[25] = ptrValue1[24] * f01 + ptrValue1[25] * f11;
                ptrResult[26] = ptrValue1[26] * f00 + ptrValue1[27] * f10;
                ptrResult[27] = ptrValue1[26] * f01 + ptrValue1[27] * f11;
                ptrResult[28] = ptrValue1[28] * f00 + ptrValue1[29] * f10;
                ptrResult[29] = ptrValue1[28] * f01 + ptrValue1[29] * f11;
                ptrResult[30] = ptrValue1[30] * f00 + ptrValue1[31] * f10;
                ptrResult[31] = ptrValue1[30] * f01 + ptrValue1[31] * f11;
                ptrResult    += 32;
                ptrValue1    += 32;
            }
            ptrEnd += 16;
            if (ptrResult < ptrEnd)
            {
                *ptrResult = *ptrValue1 * f00 + ptrValue1[1] * f10;
                ptrResult[1]  = *ptrValue1 * f01 + ptrValue1[1] * f11;
                ptrResult[2]  = ptrValue1[2] * f00 + ptrValue1[3] * f10;
                ptrResult[3]  = ptrValue1[2] * f01 + ptrValue1[3] * f11;
                ptrResult[4]  = ptrValue1[4] * f00 + ptrValue1[5] * f10;
                ptrResult[5]  = ptrValue1[4] * f01 + ptrValue1[5] * f11;
                ptrResult[6]  = ptrValue1[6] * f00 + ptrValue1[7] * f10;
                ptrResult[7]  = ptrValue1[6] * f01 + ptrValue1[7] * f11;
                ptrResult[8]  = ptrValue1[8] * f00 + ptrValue1[9] * f10;
                ptrResult[9]  = ptrValue1[8] * f01 + ptrValue1[9] * f11;
                ptrResult[10] = ptrValue1[10] * f00 + ptrValue1[11] * f10;
                ptrResult[11] = ptrValue1[10] * f01 + ptrValue1[11] * f11;
                ptrResult[12] = ptrValue1[12] * f00 + ptrValue1[13] * f10;
                ptrResult[13] = ptrValue1[12] * f01 + ptrValue1[13] * f11;
                ptrResult[14] = ptrValue1[14] * f00 + ptrValue1[15] * f10;
                ptrResult[15] = ptrValue1[14] * f01 + ptrValue1[15] * f11;
                ptrResult    += 16;
                ptrValue1    += 16;
            }
            ptrEnd += 8;
            if (ptrResult < ptrEnd)
            {
                *ptrResult = *ptrValue1 * f00 + ptrValue1[1] * f10;
                ptrResult[1] = *ptrValue1 * f01 + ptrValue1[1] * f11;
                ptrResult[2] = ptrValue1[2] * f00 + ptrValue1[3] * f10;
                ptrResult[3] = ptrValue1[2] * f01 + ptrValue1[3] * f11;
                ptrResult[4] = ptrValue1[4] * f00 + ptrValue1[5] * f10;
                ptrResult[5] = ptrValue1[4] * f01 + ptrValue1[5] * f11;
                ptrResult[6] = ptrValue1[6] * f00 + ptrValue1[7] * f10;
                ptrResult[7] = ptrValue1[6] * f01 + ptrValue1[7] * f11;
                ptrResult   += 8;
                ptrValue1   += 8;
            }
            ptrEnd += 4;
            if (ptrResult < ptrEnd)
            {
                *ptrResult = *ptrValue1 * f00 + ptrValue1[1] * f10;
                ptrResult[1] = *ptrValue1 * f01 + ptrValue1[1] * f11;
                ptrResult[2] = ptrValue1[2] * f00 + ptrValue1[3] * f10;
                ptrResult[3] = ptrValue1[2] * f01 + ptrValue1[3] * f11;
                ptrResult   += 4;
                ptrValue1   += 4;
            }
        }
예제 #3
0
 static Block2x2()
 {
     Unit = new Block2x2(1, 0, 0, 1);
 }