[omniORB] CORBA::Fixed::realMul bug

Simone Viani sviani at etasistemi.it
Wed Feb 16 12:55:06 GMT 2005


Multiplication operation has a bug for values having
leading zeros at the right of the decimal point,
making the result's digit count be greater than the
actual count.

Example:

CORBA::Fixed a = "12345.0";
CORBA::Fixed b = "0.001";

CORBA::Fixed c = a * b;
// c=12.345, c.pd_digits=7 (wrong! must be 5)

CORBA::Fixed d = "13.345";
// d.pd_digits=5, d < c (wrong! should be d > c)

CORBA::Fixed e = c - d; // assert violation...
// ... because operator- doesn't swap arguments
// to realSub which in turn exits with carry != 0

Fix:

In realMul inner loop on b, skip if current b's
digit is zero and there's no carry to propagate.

Diff for branch omni4_1_develop:

diff C5 corbaFixed.cc corbaFixed_patch.cc
*** corbaFixed.cc    Wed Feb 16 11:16:45 2005
--- corbaFixed_patch.cc    Wed Feb 16 11:43:53 2005
***************
*** 860,869 ****
--- 860,870 ----
      ad = a.PR_val()[ai];
      if (ad == 0) continue;
 
      for (bi=0; bi < b.fixed_digits(); ++bi) {
        bd = b.PR_val()[bi];
+       if (bd == 0 && carry == 0) continue;
        wi       = ai + bi;
        v        = work[wi] + ad * bd + carry;
        carry    = v / 10;
        work[wi] = v % 10;
      }

Bye,
Simone Viani




More information about the omniORB-list mailing list