The ptolemy.math.FixedPoint class does not seem to handle bit growth properly for add or subtract operations. For multiplies, the fixed point format grows automatically as part of the operation. However, no bit growth is provided for add or subtract. I would suggest that add and subtract increase the "inBits" of the new FixPoint value when the intBits field of both operands are the same. This will allow the fixed point value to grow when an "overflow" occurs during addition and subtraction.

Original code (for add):

   public FixPoint add(FixPoint arg) {
       int fracBits = Math.max(_frac_bits, arg._frac_bits);
       int intBits = Math.max(_int_bits, arg._int_bits);
       BigInteger thisValue = _alignToFraction(fracBits);
       BigInteger thatValue = arg._alignToFraction(fracBits);
       return new FixPoint(thisValue.add(thatValue), intBits, fracBits);
   }

Suggested code:

   public FixPoint add(FixPoint arg) {
       int fracBits = Math.max(_frac_bits, arg._frac_bits);
       int intBits = Math.max(_int_bits, arg._int_bits);
       if (_int_bits == arg._int_Bits)
         intBits++;
       BigInteger thisValue = _alignToFraction(fracBits);
BigInteger thatValue = arg._alignToFraction(fracBits); return new FixPoint(thisValue.add(thatValue), intBits, fracBits);
   }

--
Michael J. Wirthlin Associate Professor
Electrical and Computer Engineering  Voice: (801) 422-7601
Brigham Young University             Fax:   (801) 422-0201
459 Clyde Building                   Email: [EMAIL PROTECTED]
Provo, UT 84602                      www.ee.byu.edu/faculty/wirthlin


----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list.  Please send administrative
mail for this list to: [EMAIL PROTECTED]

Reply via email to