private static IEnumerable <int> CalculateMantissa(FloatB fb1, FloatB fb2) { var m1 = fb1._mantissa.ToList(); var m2 = fb2._mantissa.ToList(); m1.InsertRange(0, new [] { 0, 1 }); m2.InsertRange(0, new [] { 0, 1 }); var mantissa = (new Binary(m1) / new Binary(m2)).Value.ToList(); if (mantissa[0] == 1 && mantissa[1] == 0) { mantissa.RemoveRange(0, 1); mantissa.RemoveAt(mantissa.Count - 1); } else if (mantissa[0] == 0 && mantissa[1] == 1) { mantissa.RemoveRange(0, 2); } if (mantissa.Count < (int)BinaryConstants.Mantissa) { mantissa.AddRange(new int[(int)BinaryConstants.Mantissa - mantissa.Count]); } return(mantissa); }
private static IEnumerable <int> CalculateExponent(FloatB fb1, FloatB fb2) { var exp = fb1.GetExponent - fb2.GetExponent + (int)BinaryConstants.Exp; var exponent = new Bin(exp).ValueBin.ToList(); if (exponent.Count > (int)BinaryConstants.Exponent) { throw new OverflowException("Overflow"); } return(exponent); }
private static bool IsZero(FloatB fb) { var e = fb._exponent.TakeWhile(i => i == 0).Count(); return(e == (int)BinaryConstants.Exponent); }