Questions on OOP in MQL5 - page 91

 
Dmitry Fedoseev:

Why wouldn't it work all of a sudden? Three enumerations, none of them more than 10. Second grade middle school arithmetic.

3 enumerations plus 2 int , you need 4 bytes = int

int I need in the range +1000 -... +1000 , pips, that's just 2^10

int int's are worth considering, the 1 pips step is not important, 2.5-...9 pips is also possible, i.e. discreteness is not very critical

 
Igor Makanu:

3 enumerations plus 2 int , need in 4 bytes

int I need in the range +1000 -... +1000 , pips, that's just 2^10

int int's are worth considering yet, 1 pip increments are not important, you can have 2.5-...9 pps, i.e. discreteness is not so critical

There is more than enough space. INT_MAX=2147483647.

We could go tens instead of straightforwardly and bluntly, and make it 8*8*4 sparingly. You just have to think about it))) But there's no need, everything fits in anyway.

And to check - why not start cycle up to INT_MAX - the hardware will check it, not to look through the file with results by itself.

 
Dmitry Fedoseev:

More than enough space. INT_MAX=2147483647.

You can also not stupidly and straight - tens to occupy, and economically, to do in a pinch - 8*8*4. Only you need to think))) But there's no need, everything fits in anyway.

And to check - why not make cycle up to INT_MAX - it will be checked by hardware, we won't need to look through result file by ourselves.

I don't mind... I need the code to evaluate and the methodology is more important than how to convert

 
Igor Makanu:

I don't mind... I need the code to evaluate, and the testing methodology is more important than how to convert

Bitwise priming, no? It's like converting a number into a string with bitwise values. One for integers and one for dots and check. That's just for debugging purposes.

 
Alexandr Andreev:

Bitwise unwrite, no? Something like stringing a number with bitwise values. One for integers and one for dots and check. That's just for debugging purposes.

Yeah, that's clear, but how do you automate the verification?

problem, not in my example, but in the fact that I still need to pack in 3 int's of other data, I don't want to spend too much time on checking each pack


ZS: the idea is bright, but not bitwise values, but hex - from printf() you can get, or rather from stringformat()

 
Igor Makanu:

Yes it's all clear, but how to automate checking?

The problem, not in my example, but in the fact that I still need to pack in 3 int's of other data, I don't want to spend a lot of time on checking each pack


HH: good idea, but not bitwise values, but hex - we can get them from printf() or from stringformat()

)) can't figure out what's needed

   v = (V)(data & 0x3);
   d = (D)((data >> 2) & 0x7);
   t = (T)((data >> 5) & 0x7);
   uint tmp = ((data >> 8) & 0xFFF);
   param2 = (tmp & 0x800) == 0x800 ? -(int)(tmp & 0x7FF) : (int)(tmp & 0x7FF);
   tmp = data >> 20;
   param1 = (tmp & 0x800) == 0x800 ? -(int)(tmp & 0x7FF) : (int)(tmp & 0x7FF);

Do we want to automate an offset or what?

What is this check?

And we can always just check the source and converted values.

 
Igor Makanu:

I don't mind... The code needs to be evaluated, and the validation methodology is more important than how to convert

If the methodology of conversion is clear and understandable, then there's not much need for checking.

 
...
   static int        sign;
   static int        _sign;
   static int        mean;
public:
...
   int               Get() const;
   static void       Print(int val);
private:
   int               GetInt12(int val) const {return ((val&sign)>>20)|(val&mean);}
   static int        GetInt(int val) {return (val&_sign)<<20|(val&mean);}
  };
...
//------------------------------------------------------------------------
int CSetting::Get() const{
   return t<<29|d<<26|v<<24|GetInt12(param1)<<12|GetInt12(param2);
}
//------------------------------------------------------------------------
void CSetting::Print(int val){
   PrintFormat("%s, %s, %s, %i, %i",EnumToString(T(val>>29)),EnumToString(D(val>>26)),EnumToString(V(val>>24)),GetInt(val>>12),GetInt(val));
}
int CSetting::sign=1<<31;
int CSetting::_sign=1<<11;
int CSetting::mean=0xFFFFFFFF>>21;
void OnStart(void)
  {
   CSetting test(Input_p1,Input_p2,Input_T,Input_D,Input_V);
   int res=test.Get();
   Print ("int=",res);
   CSetting::Print(res);
 }
 
Vladimir Simakov:

Well it's obvious that there will be more variables for me it's better just to use byte copying of structures (probably the process does not require strong optimization of speed but convenience will be at a premium)

 
void OnStart()
  {

   int a=9;
   int b=8;
   int c=7;
   int d=12345;

   int v=pack(a,b,c,d);
   
   int a2,b2,c2,d2;
   unpack(v,a2,b2,c2,d2);
   
   Alert(a2," ",b2," ",c2," ",d2);

}

void unpack(int val,int & a,int & b,int & c,int & d){
   d=val/1000;
   val%=1000;
   c=val/100;
   val%=100;   
   b=val/10;
   a=val%10;
}

int pack(int a,int b,int c,int d){
   return(a+b*10+c*100+d*1000);
}

Cheap and cheaper