Errors, bugs, questions - page 1167

 
Swan:
maybe, but it seems to be transmitted correctly. TheGlobal Variables window rounds up, displays 17 digits.
18...
 
TheXpert:
Union caste to the rescue. It's legal in mql5 even through structures.
MQL4. What can you do?
 
artmedia70:
MQL4. What can you picture?
Isn't the new MQL4 pulled up to MQL5?
 
marketeer:
Isn't the new MQL4 pulled up to MQL5?
Not exactly. Although, judging by the Help, it's almost the same. But we will not judge. We are interested in the result.
 
artmedia70:
MQL4. What can you do?

Let's see...

Here's a script with the principle, should work for both 4 and 5

struct DoubleContainer
{
   double value;
};

struct LongContainer
{
   long value;
};

long ToLong(double value)
{
   DoubleContainer d; d.value = value;
   LongContainer l = (LongContainer)d;
   return l.value;
}

double ToDouble(long value)
{
   LongContainer l; l.value = value;
   DoubleContainer d = (DoubleContainer)l;
   return d.value;
}

void OnStart()
{
   long l = 130462919691841406;
   double d1 = (double)l;
   long l1 = (long)d1;
   double d2 = ToDouble(l);
   long l2 = ToLong(d2);
}
 
Vinin:
Not exactly. Although judging by the Helps, it's pretty much the same thing. But we're not going to judge. We're interested in the result.
I think TheXpert showed us how to get the result. There's already enough of 5's syntax in 4.
 
TheXpert:

Let's see...

Here's a script with the principle, it should work on 4 and 5

This is really weird...

#property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long l = 130462919691841406;
   //--- приведение типов
   double d1 = (double)l;
   long l1 = (long)d1;
   //--- преобразование типов
   double d2 = ToDouble(l);
   long l2 = ToLong(d2);
   //--- поглядим чё натворили
   Print("long-значение l = "+IntegerToString(l));
   Print("long l привели к типу double d1 = "+DoubleToString(d1,Digits));
   Print("double d1 привели к типу long l1 = "+IntegerToString(l1));
   Print("long l преобразовали в double d2 = "+DoubleToString(d2,Digits));
   Print("double d2 преобразовали в long l2 = "+IntegerToString(l2));
   ToDoubleString(l);
  }
//+------------------------------------------------------------------+
struct DoubleContainer
{
   double value;
};
//+------------------------------------------------------------------+
struct LongContainer
{
   long value;
};
//+------------------------------------------------------------------+
long ToLong(double value)
{
   DoubleContainer d; d.value = value;
   LongContainer l = (LongContainer)d;
   return l.value;
}
//+------------------------------------------------------------------+
double ToDouble(long value)
{
   LongContainer l; l.value = value;
   DoubleContainer d = (DoubleContainer)l;
   return d.value;
}
//+------------------------------------------------------------------+
double ToDoubleString(long long_value) {
   string long_value_str=IntegerToString(long_value);
   double double_value=StrToDouble(long_value_str);
   Print("long_value = "+IntegerToString(long_value)+", double_value = "+DoubleToString(double_value,Digits));
   return double_value;
}
//+------------------------------------------------------------------+

long, converted to double, displays zero. Although, after that double zero is normally converted back to long. I don't get it...


What the... ????????????

 
artmedia70:
And look in the debugger? There's a very small non-zero value there. It's still working, what more do you need?
 
TheXpert:
And look it up in the debugger? There is a very small non-zero value there. It still works, what else do you need?

See. I send window id (it is long) to the globe terminal (they are double). I need a set of indicators installed on different, any chart (the Expert Advisor will set them) to read the ID value of the chart of the controlling Expert Advisor and send its data to this very chart. The Expert Advisor will in its turn process all this data and then work with them. I see zero in the global terminal, and I am not so sure that the indicator will receive the necessary id of the desired chart and send its data there. I see zero. And it doesn't coincide with the chart id, on which the Expert Advisor works. I need to be sure.
If I cannot convert the data properly, I will have to use csv file. However, I want to solve the problem of data conversion without losses. And there is no loss, but addition of 2 to the true value.

I tried to convert to string - the same thing - it increases by 2 the sent value long 130462919691841406:

//+------------------------------------------------------------------+
void ToDoubleString(long long_value) {
   string long_value_str=IntegerToString(long_value);
   double double_value=StrToDouble(long_value_str);
   Print("long_value = "+long_value_str+", double_value = "+DoubleToString(double_value,Digits));
}
//+------------------------------------------------------------------+

result:

2014.07.07 00:45:08.513 LongToDouble EURUSD,H4: long_value = 130462919691841406, double_value = 130462919691841408.00000

I don't understand...

 

Ta maaa...

You have to put in a double from the long before the transfer. For global variable. There is not zero value, it's just a random dable, it can be say 1.34*e-307 can be 4.29*e+120, because there are bits of long.

After transmission, unzip from dub to long.

That's it.

Reason: