public bool Equals(Nbit other) { var e = this; Update(ref e, ref other); return(e._value == other._value); }
public static Nbit Convert(Nbit a, byte fsize) { var b = new Nbit(fsize); b.Value = a.IsNeg() ? Negate((-a)._value, fsize) : a.Value; return(b); }
public static void Update(ref Nbit a, ref Nbit b) { if (b.Size > a.Size) { a = Convert(a, b.Size); } else if (b.Size < a.Size) { b = Convert(b, a.Size); } }
public static bool PlusOverflow(Nbit a, Nbit b) { var s = a.Size > b.Size ? a.Size : b.Size; var neg = a.IsNeg(); if (b.IsNeg() != neg) { return(false); } var e = Bit.Bins[s]; var vala = a._value; var valb = b._value; var val = vala + valb; return(neg ? 2 * e - val > e / 2 : val >= e / 2); }
public static bool TimeOverflow(Nbit a, Nbit b) { var e = a.Size > b.Size ? a.Size : b.Size; var s = Bit.Bins[e]; var neg = a.IsNeg(); var negb = b.IsNeg(); if (neg && !negb) { return(b._value * (s - a._value) <= s / 2); } if (neg) { return((s - a._value) * (s - b._value) < s / 2); } return(negb ? a._value * (s - b._value) > s / 2 : a._value *b._value >= s / 2); }