private bool AbsLessThenMin(MbfFloat minValue) { if (Exponent != minValue.Exponent) { return(Exponent < minValue.Exponent); } return(Mantissa < minValue.Mantissa); }
private bool AbsGreaterThenMax(MbfFloat maxValue) { if (Exponent != maxValue.Exponent) { return(Exponent > maxValue.Exponent); } return(Mantissa > maxValue.Mantissa); }
public void Add(MbfFloat right, bool normalize = true) { if (right.IsZero) { return; } if (IsZero) { Mantissa = right.Mantissa; Exponent = right.Exponent; IsNegitive = right.IsNegitive; return; } // ensure right has largest exponent if (Exponent > right.Exponent) { var temp = ToMbfFloat(); Mantissa = right.Mantissa; Exponent = right.Exponent; IsNegitive = right.IsNegitive; right = temp; } // denormalise left to match exponents while (Exponent < right.Exponent) { Exponent += 1; Mantissa >>= 1; } // add mantissas, taking sign into account if (IsNegitive == right.IsNegitive) { Mantissa += right.Mantissa; } else { if (Mantissa > right.Mantissa) { Mantissa -= right.Mantissa; } else { Mantissa = right.Mantissa - Mantissa; IsNegitive = right.IsNegitive; } } if (normalize) { Normalize(); } }
protected bool Equals(MbfFloat mbf) { if (IsZero) { return(mbf.IsZero); } return(mbf.IsNegitive == IsNegitive && mbf.Exponent == Exponent && mbf.Mantissa == Mantissa); }
public MbfFloatParser(MbfFloat fp) : this(fp is MbfDouble) { if (fp == null) { throw new ArgumentNullException(nameof(fp)); } Mantissa = fp.Mantissa; Exponent = fp.Exponent; IsNegitive = fp.IsNegitive; }
public void Divide(MbfFloat right) { if (right.IsZero) { var max = IsDouble ? (MbfFloat)MbfDouble.Max : MbfSingle.Max; Exponent = max.Exponent; Mantissa = max.Exponent; throw new DivideByZeroException(); } if (IsZero) { return; } // signs IsNegitive = IsNegitive != right.IsNegitive; // subtract exponentials Exponent -= (byte)(right.Exponent - right.MbfBias - 8); // long division of mantissas var leftMantissa = Mantissa; var rightMantissa = right.Mantissa; Mantissa = 0; Exponent += 1; while (rightMantissa > 0) { Mantissa <<= 1; Exponent -= 1; if (leftMantissa > rightMantissa) { leftMantissa -= rightMantissa; Mantissa += 1; } rightMantissa >>= 1; } Normalize(); }