gnucobol-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [open-cobol-list] Team setup


From: Bernard Giroud
Subject: Re: [open-cobol-list] Team setup
Date: Thu Oct 28 22:17:54 2004

Hi Henry and Roger,

Specific quote :
>...
>As if the sign bit had been lost.
>I had a look in cob_add(). mpz_add() does not know anything about the size
of
>the integers involved in the add process. How can it be able to have the
>behavior of the corresponding COBOL integers ? May be I miss something.


I think you are mostly right. But one thing we must not forget is that gmp
stands for Multi Precision (AFAICR), which means a range
from -infinity to +infinity. When you start at +2147483647 (x7FFFFFFF)
and add 1 you get x80000000 which is still in the +infinity side. Fine !

Now we will get that quantity into a long but with a mpz_get_si which
is designed to return an int. I think the solution is to use mpz_get_ui
into a signed long in the first case. BTW, it seems that mpz_fits_slong_p
return false in that case, which I don't understand :-((.

The modified routine is at the end of this mail. It seems to be OK,
and no regression.

Could you tell me if it seems allright to commit ?

Bernard Giroud
Credit Lyonnais (Suisse) SA
----- Original Message -----
From: <address@hidden>
To: "Giroud, Bernard" <address@hidden>
Cc: <address@hidden>
Sent: Wednesday, October 27, 2004 4:22 PM
Subject: Re: [open-cobol-list] Team setup



Hello,

About the little bug mentionned by Roger, I made some tests with numeric.c
As Roger suggested, simply testing flag_binary_truncate fixes part of the
problem.
Adding 4 to +2147483640 gives +2147483644 : that is good.
Adding 1 to +2147483647 gives 0, but adding 2 to 2147483647 gives +1, not -1
as
Roger suggests it should do.
As if the sign bit had been lost.
I had a look in cob_add(). mpz_add() does not know anything about the size
of
the integers involved in the add process. How can it be able to have the
behavior of the corresponding COBOL integers ? May be I miss something.

I will work on improvement of the compiler internals.
If Robert is OK, I can have a look at the second bug : internal compiler
error
(req. id. 1014371).

Cheers
Henry


Selon "Giroud, Bernard" <address@hidden>:

> Hi all,
>
> We begin to be a team (I think we need to be at least 6 to try to make
> the job Keisuke did!).
>
> So we need to be a litlle bit organised.
>
> I started by numbering the different points in the TODO file.
>
> Roger, Henry, and Robert,
>
> Can you express your preferences in the list, so that everybody knows
> what's done by others.
>
> I think to remember that Roger wanted (after the little bug he
> discovered) to work on
> runtime optimisation.
>
> Robert, will one of the two bugs mentioned in the tracker suits to you ?
> If preferable, take
> the oldest...
>
> And Henry, how' are you feeling now ?
>
> I will personally start with the implementation of intrinsics.
>
> Cheers,
> --
> Bernard Giroud
> Open Source COBOL Tools Developer

Routine cob_decimal_get_binary:

static int
cob_decimal_get_binary (cob_decimal *d, cob_field *f, int opt)
{
  int overflow = 0;
  int digits = f->attr->digits;
  if (f->size <= sizeof (long))
    {
      if (COB_FIELD_HAVE_SIGN (f))
 {
   long val;
   val = mpz_get_si (d->value);
   if (!mpz_fits_sint_p (d->value) &&
    cob_current_module->flag_binary_truncate)
     {
       /* overflow */
       overflow = 1;
       if (opt & COB_STORE_KEEP_ON_OVERFLOW)
  goto overflow;
       if (opt & COB_STORE_TRUNC_ON_OVERFLOW)
  mpz_tdiv_r_ui (d->value, d->value, cob_exp10[digits]);
     }
   val = mpz_get_ui (d->value);
   if ((val <= -cob_exp10[digits] || val >= cob_exp10[digits]) &&
    cob_current_module->flag_binary_truncate)
     {
       /* overflow */
       overflow = 1;
       if (opt & COB_STORE_KEEP_ON_OVERFLOW)
  goto overflow;
       if (opt & COB_STORE_TRUNC_ON_OVERFLOW)
  val %= cob_exp10[digits];
     }
   cob_binary_set_int (f, val);
 }
      else
 {
   unsigned long val;
   if (mpz_sgn (d->value) < 0)
     mpz_abs (d->value, d->value);
   if (cob_current_module->flag_binary_truncate == 1 && !mpz_fits_uint_p
(d->value))
     {
       /* overflow */
       overflow = 1;
       if (opt & COB_STORE_KEEP_ON_OVERFLOW)
  goto overflow;
       if (opt & COB_STORE_TRUNC_ON_OVERFLOW)
  mpz_tdiv_r_ui (d->value, d->value, cob_exp10[digits]);
     }
   val = mpz_get_ui (d->value);
   if (cob_current_module->flag_binary_truncate && val >= cob_exp10[digits])
     {
       /* overflow */
       overflow = 1;
       if (opt & COB_STORE_KEEP_ON_OVERFLOW)
  goto overflow;
       if (opt & COB_STORE_TRUNC_ON_OVERFLOW)
  val %= cob_exp10[digits];
     }
   cob_binary_set_int (f, val);
 }
    }
  else
    {
      unsigned long lo;
      mpz_fdiv_r_2exp (cob_d2.value, d->value, 32);
      mpz_fdiv_q_2exp (d->value, d->value, 32);
      lo = mpz_get_ui (cob_d2.value);

      if (COB_FIELD_HAVE_SIGN (f))
 {
   long long val;
   if (!mpz_fits_sint_p (d->value))
     {
       /* overflow */
       overflow = 1;
       if (opt & COB_STORE_KEEP_ON_OVERFLOW)
  goto overflow;
       if (opt & COB_STORE_TRUNC_ON_OVERFLOW)
  /* FIXME: need truncation */;
     }
   val = mpz_get_si (d->value);
   val = (val << 32) | lo;
   if (val <= -cob_exp10LL[digits] || val >= cob_exp10LL[digits])
     {
       /* overflow */
       overflow = 1;
       if (opt & COB_STORE_KEEP_ON_OVERFLOW)
  goto overflow;
       if (opt & COB_STORE_TRUNC_ON_OVERFLOW)
  val %= cob_exp10LL[digits];
     }
   cob_binary_set_int64 (f, val);
 }
      else
 {
   unsigned long long val;
   if (mpz_sgn (d->value) < 0)
     mpz_abs (d->value, d->value);
   if (!mpz_fits_uint_p (d->value))
     {
       /* overflow */
       overflow = 1;
       if (opt & COB_STORE_KEEP_ON_OVERFLOW)
  goto overflow;
       if (opt & COB_STORE_TRUNC_ON_OVERFLOW)
  /* FIXME: need truncation */;
     }
   val = mpz_get_ui (d->value);
   val = (val << 32) | lo;
   if (val >= cob_exp10LL[digits])
     {
       /* overflow */
       overflow = 1;
       if (opt & COB_STORE_KEEP_ON_OVERFLOW)
  goto overflow;
       if (opt & COB_STORE_TRUNC_ON_OVERFLOW)
  val %= cob_exp10LL[digits];
     }
   cob_binary_set_int64 (f, val);
 }
    }
  if (!overflow)
    return 0;

 overflow:
  COB_SET_EXCEPTION (COB_EC_SIZE_OVERFLOW);
  return cob_exception_code;
}



********************************************************************************
This e-mail contains confidential information or information belonging 
to the Credit Lyonnais Group entity sending it and is intended solely 
for the addressees. Any views expressed in this message are those of 
the individual sender and its contents do not constitute a commitment 
by Credit Lyonnais unless confirmed by letter or fax. The unauthorised 
disclosure, use, dissemination or copying (either whole or partial) of 
this e-mail, or any information it contains, is prohibited. E-mails are 
susceptible to alteration and their integrity cannot be guaranteed.
Internet communications are not secured and therefore Credit Lyonnais 
shall not be liable for this e-mail if modified or falsified. If you 
are not the intended recipient of this e-mail, please delete it 
immediately from your system and notify the sender of the wrong 
delivery and the mail deletion.
********************************************************************************



reply via email to

[Prev in Thread] Current Thread [Next in Thread]