示例#1
0
        public static int logmath_add(Pointer <logmath_t> lmath, int logb_x, int logb_y)
        {
            logadd_t t = lmath.Deref.t;
            int      d, r;

            /* handle 0 + x = x case. */
            if (logb_x <= lmath.Deref.zero)
            {
                return(logb_y);
            }
            if (logb_y <= lmath.Deref.zero)
            {
                return(logb_x);
            }

            if (t.table_uint8.IsNull)
            {
                return(logmath_add_exact(lmath, logb_x, logb_y));
            }

            /* d must be positive, obviously. */
            if (logb_x > logb_y)
            {
                d = (logb_x - logb_y);
                r = logb_x;
            }
            else
            {
                d = (logb_y - logb_x);
                r = logb_y;
            }

            if (d < 0)
            {
                /* Some kind of overflow has occurred, fail gracefully. */
                return(r);
            }
            if ((uint)d >= t.table_size)
            {
                /* If this happens, it's not actually an error, because the
                * last entry in the logadd table is guaranteed to be zero.
                * Therefore we just return the larger of the two values. */
                return(r);
            }

            switch (t.width)
            {
            case 1:
                return(r + ((t.table_uint8)[d]));

            case 2:
                return(r + ((t.table_ushort)[d]));

            case 4:
                return(checked ((int)(r + ((t.table_uint32)[d]))));
            }
            return(r);
        }
        public static int fast_logmath_add(Pointer <logmath_t> lmath, int mlx, int mly)
        {
            logadd_t t = lmath.Deref.t;
            int      d, r;

            /* d must be positive, obviously. */
            if (mlx > mly)
            {
                d = (mlx - mly);
                r = mly;
            }
            else
            {
                d = (mly - mlx);
                r = mlx;
            }

            return(r - ((t.table_uint8)[d]));
        }
示例#3
0
 public logmath_t()
 {
     t = new logadd_t();
 }