/* Operators */ public static MiniFloat operator +(MiniFloat Augend, MiniFloat Addend) { MiniFloat m = Augend.Copy(); MiniFloat n = Addend.Copy(); m.Mantissa = '1' + m.Mantissa; n.Mantissa = '1' + n.Mantissa; Normalize(ref m, ref n); if (m.Signbit == '0' && n.Signbit == '0') { return(add(m, n)); } else if ((m.Signbit == '1' && n.Signbit == '0') || (n.Signbit == '1' && m.Signbit == '0')) { if (m.Mantissa > n.Mantissa) { return(sub(m, n)); } else if (n.Mantissa > m.Mantissa) { return(sub(n, m)); } else /* Equal */ return { (new MiniFloat()); //Zero } } else //Both are negative { MiniFloat r = add(m, n); r.Signbit = '1'; return(r); } }
/* -- End of Operators for Concatenation -- */ public static Binary operator +(Binary Augend, Binary Addend) { Binary m = Augend.Copy(); Binary n = Addend.Copy(); /* Normalize to the longest one */ int l; if (m.Length > n.Length) { l = m.Length; for (int i = n.Length; i < m.Length; i++) { n = '0' + n; } } else if (m.Length < n.Length) { l = n.Length; for (int i = m.Length; i < n.Length; i++) { m = '0' + m; } } else { l = m.Length; } Binary c = new Binary(l); for (int i = l - 1; i >= 0; i--) { int x = MainClass.ValueOf(m[i]) + MainClass.ValueOf(n[i]) + MainClass.ValueOf(c[i]); c[i] = MainClass.Character(x); if (c[i] == '2' || c[i] == '3') { c[i] = (c[i] == '2' ? '0' : '1'); if (i - 1 < 0) //If it's the last one... { c = '1' + c; } else { c[i - 1] = '1'; } } } return(c); }