[omniORB] bugs in CORBA::Fixed class

Simone Viani sviani at etasistemi.it
Wed Jul 7 13:40:49 BST 2004


Duncan Grisby wrote:

>On Monday 14 June, Simone Viani wrote:
>
>[...]
>
>>2) Method round()
>>
>>   At first glance there's a typo, variable 'cut' instead of 'i'
>>   in the core loop that prevent the needed propagation.
>>
>
>Thanks. I've checked in a variant of your changes that I believe fixes
>the issues.
>
>Cheers,
>
>Duncan.
>

I'm very sorry, but new version still doesn't work well
when rounding a number with all digits equal to 9, as in
my previous example:

  a = 1;
  b = 3;
  c = a / b * b;    // c = 0.9999999...
  d = c.round(2);   // invalid number! should be d = 1

In this case we need to add a leading digits (equal to 1)
to the work buffer, for which it must reserve space and we
have to loop one more step. Following your code style
one possible solution is:

  CORBA::Octet work[OMNI_FIXED_DIGITS + 1]; // reserve extra byte!
  memcpy(work, pd_val, OMNI_FIXED_DIGITS);
  work[OMNI_FIXED_DIGITS] = 0;              // init extra byte!

  int i = cut;
  for (i = cut; i <= OMNI_FIXED_DIGITS; ++i) // i less or equal!
  ...

Hope this may help,
bye




More information about the omniORB-list mailing list