C#고정밀 구현(반제품)

1167 단어 C#
개학준비 했으니까 시간이 없어서 +호만 이루어졌다고 썼고 나머지는 나중에 얘기할게요.
using System; using System.Text; namespace high_precision_calculate { class number { public number(string str) { v = new StringBuilder(str); } public number() { v = new StringBuilder(0); } public StringBuilder v { get; set; } public static number operator + (number l, number r) {//보충 2비트 int ll = l.v.Length; int rl = r.v.Length; int sub = ll - rl; if (sub > 0) {r.v.Insert (0, new string ('0', sub + 1); l.v.Insert (0, new string ('0', 1));else if (sub < 0) { l.v.Insert(0, new string('0', -sub + 1)); r.v.Insert(0, new string('0', 1)); }//int count = l.v.Length;//보충된 것이 무엇인지 모르기 때문에 길이char[]result = new char[count + 1];//result bool flag = false;for (int i = count - 1; i >= 0; i--) { int a = Convert.ToInt32(l.v[i]) - 48; int b = Convert.ToInt32(r.v[i]) - 48; int c = a + b; if (flag) { c++; flag = false; }; if (c >= 10) { flag = true; c -= 10; } result[i] = Convert.ToChar(c + 48); } return new number(Convert.ToInt32(new string(result)).ToString()); } public static number operator *(number l, number r) {//TODO number result = new number(); return result; } } }

좋은 웹페이지 즐겨찾기