Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }