Features of the mql5 language, subtleties and tricks - page 145

 
TheXpert:

I think the second number has invalid double format, but it is still validated in both printer and operations.

Valid.

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280

void OnStart()
{
  double Num = 0;
  
  _W(Num) = (uchar)1;
  
  for (int i = 0; i < 324; i++)
    Num *= 10;
    
  Print(Num); // 4.940656458412466
}
 
fxsaber:

Valid.

Compare as I showed in the example aboveNum!=Num- if true, then this double is invalid, but what Print() writes there ... well, it's like a mystery behind the seven seals

 
Igor Makanu:

Compare as I showed in the example aboveNum!=Num- if true, then this double is invalid, and what Print() writes there ... Well, it's like a secret behind the seven secrets.

Of course, it is false. This is a normal number. NaN is not on the subject at all.

 
fxsaber:


yes, MathIsValidNumber says true.

 
TheXpert:

yes, MathIsValidNumber says true.

This is how this number is obtained through calculation.

void OnStart()
{
  double Num = 5;
    
  for (int i = 0; i < 324; i++)
    Num /= 10;
    
  Print(0.1 * Num == 0); // true
}
 
void OnStart()
{
  double Num = 5;
    
  for (int i = 0; i < 324; i++)
   { Num /= 10;
    
  Print(Num, " : ", 0.1 * Num == 0); // true
  }
  Print(Num!=Num);
  Print(DBL_MIN);
}

2019.10.28 17:05:40.503 tst1 (EURUSD,H4) 4.940656458412465e-323 : true

2019.10.28 17:05:40.503 tst1 (EURUSD,H4) 4.940656458412465e-324 : true

2019.10.28 17:05:40.503 tst1 (EURUSD,H4) false

2019.10.28 17:05:40.503 tst1 (EURUSD,H4) 2.225073858507201e-308

I think we are over the limit of accuracy double

UPD:

that's right:

void OnStart()
{
  double Num = 5;
    
  for (int i = 0; i < 324; i++)
   { Num /= 10;
    
//  Print(Num, " : ", 0.1 * Num == 0); // true
  Print(Num, " : ",Num - DBL_MIN > 0.0 );
  }
  Print(Num!=Num);
  Print(DBL_MIN);
}
//_______________________________________________________________________
 
fxsaber:
I don't understand this one.


DBL_MIN is a non-minimal positive double.

DBL_MIN returns a normalised number, below there are denormalised

#include <limits>
#include <iostream>
using namespace std;

int main() {
        cout << numeric_limits<double>::min() << "  " << numeric_limits<double>::denorm_min() << endl;
}

2.22507e-308 4.94066e-324

 

Anyway, we've established, I guess, the well-known statement that there are positive integers less than DBL_MIN.

#define  DBL_MIN_CORRECT (5 e-324) // Минимальное положительное double-значение
 
fxsaber:
Anyway, we must have found out the well-known statement that there are positive integers less than DBL_MIN.

so yes... but the question of dividing by zero remains open?

The number 4.940656458412465e-324 is definitely not zero, and dividing by such numbers is forbidden?

 
Igor Makanu:

so yes... but the question of dividing by zero is still open, isn't it?

It was closed from the very first post. When a minimum number is multiplied by something less than one, you get zero.

Reason: