Exemplo n.º 1
0
        public Pi()
        {
            List <string> formulaList = new List <string>()
            {
                "#eg. pi = 16 * arctan(1/5) - 4 * arctan(1/239) [Machin]",
                "Stormer + 176 57 + 28 239 - 48 682 + 96 12943",
                "Stomer + 24  8 + 8  57 + 4 239",
                "Gauss + 48 18 + 32  57 - 20 239",
                "Machin + 16  5 - 4 239"
            };
            Regex regex = new Regex(@"\s+");

            foreach (string s in formulaList)
            {
                if (s == null)
                {
                    break;
                }
                if (s.Length == 0 || s[0] == '#')
                {
                    continue;
                }
                string[] ss = regex.Split(s);
                if (ss.Length % 3 != 1)
                {
                    throw new ApplicationException("ini文件栏目数不正确");
                }
                ThePi thePi = new ThePi(ss[0]);
                for (int i = 1; i < ss.Length; i += 3)
                {
                    thePi.Add(new ThePi.Term(ss[i][0] == '+', int.Parse(ss[i + 1]), int.Parse(ss[i + 2])));
                }
                list.Add(thePi);
            }
        }
Exemplo n.º 2
0
 /* 从 ini 文件中读入初始配置,其格式如下:
  # eg. pi = 16 * arctan(1/5) - 4 * arctan(1/239) [Machin]
  # Stormer  + 176 57 + 28 239 - 48 682 + 96 12943
  # Stomer   +  24  8 +  8  57 +  4 239
  # Gauss    +  48 18 + 32  57 - 20 239
  # Machin   +  16  5 -  4 239
  */
 public Pi(string iniFileName)
 {
     using (StreamReader sr = new StreamReader(iniFileName))
     {
         Regex regex = new Regex(@"\s+");
         for (;;)
         {
             string s = sr.ReadLine();
             if (s == null)
             {
                 break;
             }
             if (s.Length == 0 || s[0] == '#')
             {
                 continue;
             }
             string[] ss = regex.Split(s);
             if (ss.Length % 3 != 1)
             {
                 throw new ApplicationException("ini文件栏目数不正确");
             }
             ThePi thePi = new ThePi(ss[0]);
             for (int i = 1; i < ss.Length; i += 3)
             {
                 thePi.Add(new ThePi.Term(ss[i][0] == '+', int.Parse(ss[i + 1]), int.Parse(ss[i + 2])));
             }
             list.Add(thePi);
         }
     }
 }