Errors, bugs, questions - page 719

 
ALozovoy:

Go to your profile and select Service Desk


Thank you
 
Rosh:

. . a new, more complete example for the Print function has been added to the help:

void OnStart()
  {
//--- выведем DBL_MAX с помощью Print(), это равносильно PrintFormat(%%.16G,DBL_MAX)
   Print("---- как выглядит DBL_MAX -----");
   Print("Print(DBL_MAX)=",DBL_MAX);
//--- теперь выведем число DBL_MAX с помощью PrintFormat()
   PrintFormat("PrintFormat(%%.16G,DBL_MAX)=%.16G",DBL_MAX);
//--- Вывод в журнал "Эксперты"
// Print(DBL_MAX)=1.797693134862316e+308
// PrintFormat(%.16G,DBL_MAX)=1.797693134862316E+308
 
//--- посмотрим как выводится тип float
   float c=(float)M_PI; // нужно явно приводить к целевому типу
   Print("c=",c, "    Pi=",M_PI, "    (float)M_PI=",(float)M_PI);
// c=3.14159    Pi=3.141592653589793    (float)M_PI=3.14159
   
//--- покажем, что может произойти при арифметических операциях над вещественными типами
   double a=7,b=200;
   Print("---- перед арифметическими операциями");
   Print("a=",a,"   b=",b);
   Print("Print(DoubleToString(b,16))=",DoubleToString(b,16));
//--- разделим a на b (7/200)
   a=a/b;
//--- теперь как будто восстановим значение в переменной b
   b=7.0/a; // ожидается, что b=7.0/(7.0/200.0)=>7.0/7.0*200.0=200 - но это не так
//--- выведем вновь вычисленное значение b
   Print("----- после арифметических операций");
   Print("Print(b)=",b);
   Print("Print(DoubleToString(b,16))=",DoubleToString(b,16));
//--- вывод в журнал "Эксперты"
// Print(b)=200.0
// Print(DoubleToString(b,16))=199.9999999999999716 (видим, что на самом деле b уже не равно 200.0)   
 
//--- создадим очень маленькое значение epsilon=1E-013
   double epsilon=1 e-13;
   Print("---- создадим очень маленькое число");
   Print("epsilon=",epsilon); // получим   epsilon=1E-013
//--- теперь вычтем эпсилон из числа b и выведем снова значение в журнал "Эксперты"
   b=b-epsilon;
//--- выводим двумя способами
   Print("---- после вычитания epsilon из переменной b");
   Print("Print(b)=",b);
   Print("Print(DoubleToString(b,16))=",DoubleToString(b,16));
//--- вывод в журнал "Эксперты"
// Print(b)=199.9999999999999  (теперь значение b после вычитания эпсилон не может округлиться до 200)
// Print(DoubleToString(b,16))=199.9999999999998578
//    (теперь значение b после вычитания эпсилон не может округлиться до 200)
  }

Since you dealt with this issue, could you explain where the extra digits come from, they are marked in red.

I just previously thought that for IEEE 754 the number of significant digits can not exceed 17, and not after the decimal point, but all.

 
victorg:

I just used to think that for IEEE 754 the number of significant digits cannot exceed 17, and not the decimal point, but the total.

To be honest, it never bothered me. But here are a couple of links if you're interested:

I don't guarantee there will be answers to these questions, but they might be interesting to read.

IEEE floating point - Wikipedia, the free encyclopedia
  • en.wikipedia.org
arithmetic formats: sets of binary and decimal floating-point data, which consist of finite numbers (including signed zeros and subnormal numbers), infinities, and special "not a number" values (NaNs) interchange formats: encodings (bit strings) that may be used to exchange floating-point data in an efficient and compact form rounding rules...
 
Rosh:

Honestly, it never bothered me.

There must be something wrong with the DoubleToString function.

void OnStart()
  {
  double a=2000000.0/3.0;
  Print(DoubleToString(a,30));
  }

Test (EURUSD,D1)666666.6666666666278616

This is the function that generates unnecessary significant digits. They should not be there.

Документация по MQL5: Преобразование данных / DoubleToString
Документация по MQL5: Преобразование данных / DoubleToString
  • www.mql5.com
Преобразование данных / DoubleToString - Документация по MQL5
 
victorg:

There must be something wrong with the DoubleToString function.

Test (EURUSD,D1)666666.6666666666278616

This is the function that generates unnecessary significant digits. There should not be any.

Have you got to DoubleToString? :) Again, not claiming anything: the Handbook says literally the following:

"If the digits value lies in the range 0 to 16, the string representation of the number will be retrieved with the specified number of decimal places. If the digits value lies between -1 and -16, then a string representation of the number in scientific format with the number of decimal places specified will be obtained. In all other cases, the number string will have 8 decimal places".

You have specified a value of 30. According to the description in the Reference Manual, the string value of the number should have 8 decimal places in this case.

 
Yedelkin:

Got to DoubleToString? :) Again, not claiming anything: the Reference Manual says literally the following:

You have a value of 30. Judging by the description in the Reference Manual, the string value of the number in this case should contain 8 decimal places at all.

The Handbook also has a minus sign in this place :)
 
Во всех остальных случаях число строковое значение числа будет содержать 8 знаков после запятой".
And the underlined word in the sentence is redundant. :)
 
Rosh:
The reference book also has a minus sign in this place :)

I copied it from here: https://www.mql5.com/ru/docs/convert/doubletostring

The phrase I highlighted, "In all other cases, the string value of the number will have 8 decimal places" does not seem to contain a minus sign :/

Документация по MQL5: Преобразование данных / DoubleToString
Документация по MQL5: Преобразование данных / DoubleToString
  • www.mql5.com
Преобразование данных / DoubleToString - Документация по MQL5
 
tol64:
And the underlined word in the sentence is redundant. :)
Well, it's been ages :)
 

My question got lost.

https://www.mql5.com/ru/forum/1111/page721#comment_179003

The warrant is still pending.