Errors, bugs, questions - page 705

 
Yedelkin:
And let's leave the question about Print()'s defects unanswered, shall we? :)
As you like.
 
victorg:
Whatever.

OK. Then I'll take the nerve. So, the description of the Print() function says that "data of the double type are printed with the precision of 16 decimal digits after the point". In fact, it turns out that the Print() function outputs somewhat rounded data:

void OnStart()
  {
   double a,b;

   a=7.0/200.0;
   b=7.0/a;
   Print("Print(b)=",b);
   Print("Print(DoubleToString(b,16))=",DoubleToString(b,16));
  }

ND 0 victorg2 (EURUSD,M1) 11:04:42 Print(b)=200.0
MP 0 victorg2 (EURUSD,M1) 11:04:42 Print(DoubleToString(b,16))=199.9999999999999716
Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
  • www.mql5.com
Основы языка / Типы данных / Вещественные типы (double, float) - Документация по MQL5
 
Yedelkin:

OK. Then I'll take the nerve. So, the description of the Print() function says that "data of the double type are printed with the precision of 16 decimal digits after the point". Actually it turned out that the Print() function produces slightly rounded data:

ND 0 victorg2 (EURUSD,M1) 11:04:42 Print(b)=200.0

MP 0 victorg2 (EURUSD,M1) 11:04:42 Print(DoubleToString(b,16))=199.999999999999999716

123.4567890123456(7>5, therefore rounded up)

It seems to be as described. What is the fault? Are zeros not printed?
 
MetaDriver:
Everything seems to fit the description. What's the problem? Are zeros not printed?
The bug is that the Print() function does not print"Data of the double type accurate to 16 decimal digits after the dot".
 
Yedelkin:
The bug is that the Print() function does not output"Data of type double with an accuracy of 16 decimal digits after the dot".

check

 Print("Print(b)="+ b);
 
sergeev:

check

Didn't take the trouble to check.

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
void OnStart()
  {
   double a,b;
   a=7.0/200.0;
   b=7.0/a;
   //Print("Print(b)=",b);
   Print("Print(b)="+b);
   Print("Print(DoubleToString(b,16))=",DoubleToString(b,16));
  }
//+------------------------------------------------------------------+

First of all, the compiler generates "implicit conversion from 'number' to 'string' victorg2.mq5 12 22".

Second,

IS 0 victorg2 (EURUSD,M1) 17:46:45 Print(b)=200
PJ 0 victorg2 (EURUSD,M1) 17:46:45 Print(DoubleToString(b,16))=199.9999999999999716

 

Use the appropriate PrintFormat function for full format control:

void OnStart()
  {
   double a,b;
   a=7.0/200.0;
   b=7.0/a;
   printf("Format: %.15lf",b);
   PrintFormat("Format: %.15lf",b);
  }

Format: 199.999999999999970
Format: 199.999999999999970
Print defaults to the normal rounding mode of double to 4 digits. We will correct the documentation.
Документация по MQL5: Общие функции / PrintFormat
Документация по MQL5: Общие функции / PrintFormat
  • www.mql5.com
Общие функции / PrintFormat - Документация по MQL5
 

Please give pointers (handles) to structures (preferably also to arrays, including static ones).

Wrapping in classes is often a bad solution:

struct SEmpty
  {
  };
  
class CEmpty
  {
  };
void OnStart()
  {
   Print("sizeof(SEmpty) = ",sizeof(SEmpty));   
   Print("sizeof(CEmpty) = ",sizeof(CEmpty));
  }
2012.04.07 20:49:38 SizeOf_Test (USDJPY,M30) sizeof(CEmpty) = 16
2012.04.07 20:49:38 SizeOf_Test (USDJPY,M30) sizeof(SEmpty) = 0
 
MetaDriver:

Please give pointers (handles) to structures (preferably to arrays as well, including static ones).

In what sense and why?

 
Renat:

1. in what sense and

2. why?

1.

CEmpty  *C[];  // Это работает.
SEmpty  *S[];  // Error: 'SEmpty' - class type expected SizeOf_Test.mq5 19      1

To create arrays of pointers to structures (arrays). with subsequent initialization for(i){ S[i] = GetPointer(StaticStruct[i]); }

2. to keep solid (packed) arrays of meaningful data.

Important when dealing with data output to raw OpenCL buffers (or sending to DLL, writing to files, etc.)

At the same time, it is possible to reorder data accesses (for example, when sorting pointers) without rewriting the data.

Reason: