예제 #1
0
        public int Divide(Q32 other)
        {
            bool isResultNegative = (this.RawLongValue < 0) ^ (other.RawLongValue < 0);
            long num    = (Math.Abs(RawLongValue) << FractionLength) / Math.Abs(other.RawLongValue);
            int  result = (int)num;

            if (isResultNegative)
            {
                result *= -1;
            }
            return(result);
        }
예제 #2
0
        public int Multilpy(Q32 other)
        {
            bool isResultNegative = (this.RawLongValue < 0) ^ (other.RawLongValue < 0);
            long num    = Math.Abs(RawLongValue) * Math.Abs(other.RawLongValue);
            int  result = (int)(num >> FractionLength);

            if (isResultNegative)
            {
                result *= -1;
            }
            return(result);
        }
예제 #3
0
        public int Divide(Q32 a)
        {
            long num = (this.RawLongValue << FractionLength) / a.RawLongValue;

            // Divisor is greater than Dividened OR result is lower than zero
            if (this.RawLongValue == a.RawLongValue ||
                this.RawLongValue == -a.RawLongValue)
            {
                return((int)num);
            }
            if (a.RawLongValue > this.RawLongValue ||
                num < 0 << FractionLength)
            {
                int positiveOne = 1 << FractionLength;
                num += positiveOne;
            }
            return((int)num);
        }
예제 #4
0
 internal Fixed(Q32 fixedPoint)
 {
     FixedPoint = fixedPoint;
 }
예제 #5
0
        public int Subtract(Q32 other)
        {
            long num = this.RawLongValue - other.RawLongValue;

            return((int)num);
        }
예제 #6
0
        public int Add(Q32 other)
        {
            long num = this.RawLongValue + other.RawLongValue;

            return((int)num);
        }
예제 #7
0
        public int Subtract(Q32 a)
        {
            long num = this.RawLongValue - a.RawLongValue;

            return((int)num);
        }
예제 #8
0
        public int Add(Q32 a)
        {
            long num = this.RawLongValue + a.RawLongValue;

            return((int)num);
        }
예제 #9
0
        public int Multilpy(Q32 a)
        {
            long num = this.RawLongValue * a.RawLongValue;

            return((int)(num >> FractionLength));
        }