Errors, bugs, questions - page 3108

 
Nikolai Semko #:

Got it.
Oh, this eclipse corridor...

I've got time going on in my demo since no connection and it's been 40 hours.

 
Nikolai Semko #:

Can't skip new versions of products, although it was fine before.


Looks like I'm not the one with the problem.
build 3110

Yesterday we had problems connecting to the MetaQuotes-Demo server, which is used to validate Marketplace products, among other things.

We fixed this bug yesterday and re-checked all the products that failed validation due to technical reasons.

We apologize for the inconvenience.

If we have accidentally missed your product and didn't re-check it, please do it yourself. The validation should now work as normal.

 

Here is a sample code:

//+------------------------------------------------------------------+
#property strict
//+------------------------------------------------------------------+
void OnStart()
  {
  uint iCurrent =722;
  int  iinterval=1000;         
  int  iNext=(int)(iCurrent-iinterval/2); // 722-500=222
  Print ("Current :",iCurrent);
  Print ("iNext   :",iNext);
  long  temp=(long)(iNext-iCurrent); //предупреждений нет ожидаем Лонг -500
  Print ( " temp (long):",temp);//int - uint ->uint Result: uint -- oшибка!

  Print ( " delta(&int)"+string((int)(iNext-iCurrent)));    // неожиданный успех  
  Print ( " delta(&long)"+string((long)(iNext-iCurrent)));  // опять штанга
  //-----------------------------------
 }

Result:

2021.11.23 13:07:35.931 testUint (Volatility 75 Index,M15)      Current :722
2021.11.23 13:07:35.932 testUint (Volatility 75 Index,M15)      iNext   :222
2021.11.23 13:07:35.932 testUint (Volatility 75 Index,M15)       temp (long):4294966796
2021.11.23 13:07:35.932 testUint (Volatility 75 Index,M15)       delta(&int)-500
2021.11.23 13:07:35.932 testUint (Volatility 75 Index,M15)       delta(&long)4294966796

Can someone explain - why

long  temp=(long)(iNext-iCurrent);

gives

4294966796

and not -500.

I don't know what's going on in my head... (

 
Mikhail Dovbakh #:

Here is a sample code:

Result:

Can someone explain - why

gives

and not -500.

I don't know what's going on in my head... (

long temp=(long)iNext-iCurrent;

https://www.mql5.com/ru/docs/basis/types/casting

You have got iNext reduced to unsigned integer first. Then the unsigned integer result is converted to long.

In my example, iNext is immediately cast to the long type, so iCurrent is also cast to the long type, but implicitly. The result is immediately converted to long

Документация по MQL5: Основы языка / Типы данных / Приведение типов
Документация по MQL5: Основы языка / Типы данных / Приведение типов
  • www.mql5.com
Приведение типов - Типы данных - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Slava #:

The question was why this type order does not give the right result. I can only assume that it depends on the type hierarchy order in the expression. If the types are in hierarchical order in the expression at runtime, the answer is correct, and if not, then a non-explicit type conversion violating the hierarchy may change the value of the variable.

long temp=(long)((int)iNext-(uint)iCurrent); 

In general, a non-explicit type conversion violates the hierarchy.

 
MetaQuotes #:

Yesterday we had problems connecting to the MetaQuotes-Demo server, which is used, among other things, for validating Marketplace products.

We corrected this problem yesterday and re-checked all the products that could not pass the validation due to technical reasons.

We apologize for any inconvenience.

If we have accidentally missed your product and it is not revalidated, please do it yourself. The check should now work as normal.

Thank you!
Everything is working now.
 
Slava #:

https://www.mql5.com/ru/docs/basis/types/casting

You have first got the iNext cast to an unsigned integer. Then the unsigned integer result is converted to long.

In my example, iNext is immediately cast to the long type, so iCurrent is also cast to the long type, only implicitly. The result is immediately cast to long

you can see why

 Print ( " delta(&int)"+string((int)(iNext-iCurrent)));    // неожиданный успех 

и

int itemp=(int)(iNext-iCurrent); 


gives the right result?

Following your description , first we cast iNext to an unsigned integer. Then unsigned integer result is converted to integer with signed.

Right?

 

Trend line not magnetised to Low red candle(EURUSD, M5;Precise time scale; Magnetisation: 15)


 
Mikhail Dovbakh #:

then explain why.

и

int itemp=(int)(iNext-iCurrent); 


gives the right result?


Easily

an unsigned integer with a length of 32 bits 4294966796 when converted to a signed integer of the same dimension gives -500

 
Valeriy Yastremskiy #:

The question was why this type order does not give the right result. I can only assume that it depends on the type hierarchy order in the expression. If the types are in hierarchical order in the expression at runtime, the answer is correct, and if not, then a non-explicit type conversion violating the hierarchy may change the value of the variable.

Zy In general a non-explicit type conversion and a violation of the hierarchy.

I already gave you the link https://www.mql5.com/ru/docs/basis/types/casting

It says it all in great detail. Read it from beginning to end without missing anything

Документация по MQL5: Основы языка / Типы данных / Приведение типов
Документация по MQL5: Основы языка / Типы данных / Приведение типов
  • www.mql5.com
Приведение типов - Типы данных - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
Reason: