[omniORB] bugs in CORBA::Fixed class

Simone Viani sviani at etasistemi.it
Mon Jun 14 19:40:04 BST 2004


1) Function absCmp(a, b)

   Returns bad result in cases as a=0.1 and b=0.0.
   Bottom lines are:

     if (ai > 0) return  1;
     if (bi > 0) return -1;

   but in my tests it works better:

     if (ai >= 0) return  1;
     if (bi >= 0) return -1;

2) Method round()

   At first glance there's a typo, variable 'cut' instead of 'i'
   in the core loop that prevent the needed propagation.

   Despite that, it would fail if propagation causes a leading
   digit to be added (as from 9.99 to 10.00).

   Moreover I think the overflow exception should not arise
   while rounding, even in the following example:

    a = 1.0;
    b = 3.0;
    c = a / b * b;    // c = 0.999999999...
    d = c.round(2);   // d = 1.00 no need to overflow!

   So this is my version of the core:

     // result will have at least 'new_digits' digits
     const int new_digits = pd_digits - cut;

     // copy only significant digits
     CORBA::Octet work[OMNI_FIXED_DIGITS];
     memcpy(work, pd_val + cut, new_digits);
     // initialize leading digit
     work[new_digits] = 0;

     int i;
     for (i = 0; i <= new_digits; ++i) {
       if (++work[i] <= 9) break;
       work[i] = 0;
       assert(i != new_digits);
       if (i == new_digits) {
         // Overflow should never occur!
       }
    }

    // calculate actual digit count
    if (++i < new_digits) i = new_digits;
    // construct result from work buffer,
    // the constructor set to zero extra leading digits
    return CLDecimalBase(work, i, scale, pd_negative);

Bye




More information about the omniORB-list mailing list