# bitand, bitor

5 messages
Open this post in threaded view
|

## bitand, bitor

 Hi there, the recent bug activity about bitand, bitor & the like made me wonder and look a bit into the functions themselves. Maybe I miss something, but why at all does one need these contraptions? As they are written, besides argument parsing, now these functions use an absurd detour via converting their arguments to "binary" string, then to ascii codes, then make string substitutions, then again convert back to floats - all this is certainly not performant. Why can't one just use int32(x) & int32(y)? Is there a consideration of MAXINT? (a float can represent a 52bit integer without loss of precision, which is more than 32bit -- consider dec2hex(2^53+[-2:2]) But even then, that could be treated appropriately without waiting for int64, say, with a=2^32 z=double(int32(x/a) & int32(y/a))*a z=z+double(int32(x-z) & int32(y-z)) Enrico
Open this post in threaded view
|

## Re: bitand, bitor

 Hi Enrico, These functions have been written by a developper that has left the team and I don't why bitor() and bitand() are coded in this way. For the time being, I've just dealed with argument check without paying attention to the algorithm. But you're totally right, I'll use & and | operators. Thanks Regards Pierre Enrico Segre a écrit : > Hi there, > the recent bug activity about bitand, bitor & the like made me wonder > and look a bit into the functions themselves. Maybe I miss something, > but why at all does one need these contraptions? As they are written, > besides argument parsing, now these functions use an absurd detour via > converting their arguments to "binary" string, then to ascii codes, then > make string substitutions, then again convert back to floats - all this > is certainly not performant. Why can't one just use int32(x) & > int32(y)? > Is there a consideration of MAXINT? (a float can represent a 52bit > integer without loss of precision, which is more than 32bit -- consider > dec2hex(2^53+[-2:2]) But even then, that could be treated appropriately > without waiting for int64, say, with > > a=2^32 > z=double(int32(x/a) & int32(y/a))*a > z=z+double(int32(x-z) & int32(y-z)) > > Enrico >   -- =================================================== Pierre MARECHAL INRIA - Centre de Recherche de Paris - Rocquencourt Domaine de Voluceau - B.P. 105 78153 Le Chesnay Cedex =================================================== Equipe-Projet Scilab Bâtiment 1B - Bureau 008 Email : [hidden email] ===================================================
Open this post in threaded view
|

## SciFunction

 Hello, I'm trying to interface an optimisation method under scilab (the optimization method is in fortran and I'm writing the interface in C). My question is: how to retrieve the output parameters of a call to SciFunction ? The following program is called several times during the run of the optimization: ///////////////////////////////////// //  First I create some parameters. The first one will contain the "x" vector and the second one the gradient of the output (I do this to give the correct size to the stack. If I don't do this, scilab says it doesn't know the ibegin + 1 parameter).   // Create the first variable: x   n_x1_tmp = n_x;   m_x1_tmp = m_x;   CreateVar(ibegin,"d",&n_x1_tmp,&m_x1_tmp,&l_x1_tmp);   for(i=0;i0)     {       sciprint("conmin: error when calling objective function\n");       return 0;     } /* End If */   n1 = ndv + 2; //////////////////////////////////// // Now I get the parameters via GetRhsVar. I hope that the size of the ibegin and ibegin+1 parameters are set correctly by SciFunction (first free the memory and then mallocated correctly to get the output parameters).   // Get fobj   GetRhsVar(ibegin,  "d",&n_fobj_tmp, &m_fobj_tmp, &l_fobj_tmp);   // Get gradient of fobj   GetRhsVar(ibegin+1,"d",&n_dfobj_tmp,&m_dfobj_tmp,&l_dfobj_tmp); ///////////////////////////////////// // Finally, I store all the output parameters in temporary arrays (because just after the objective function, I called the constraints also via SciFunction).   // Fill C2F(cnmn1).obj: objective function value   C2F(cnmn1).obj = *dstk(l_fobj_tmp);   // DF(N1) Analytic gradient of the objective function for the current decision variables, X(I).  DF(I) contains the partial derivative   //        of OBJ with respect to X(I).  Calculate DF(I), I = 1, NDV if INFO = 3 or INFO = 4 and if NFDG = 0 or NFDG = 2.   double * DF = (double *)malloc(n1*sizeof(double));   // Fill DF(N1): gradient of objective function value   for(j=0;j
Open this post in threaded view
|

## Re: SciFunction

Open this post in threaded view
|