MQL5Book/Scripts/p4/MathExp.mq5
super.admin 1c8e83ce31 convert
2025-05-30 16:09:41 +02:00

40 lines
1.5 KiB
MQL5

//+------------------------------------------------------------------+
//| MathExp.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#define PRT(A) Print(#A, "=", (A))
//+------------------------------------------------------------------+
//| Custom implementation of binary logarithm |
//+------------------------------------------------------------------+
double Log2(double value)
{
return MathLog(value) / M_LN2;
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
PRT(MathExp(0.5)); // 1.648721270700128
PRT(MathPow(M_E, 0.5));// 1.648721270700128
PRT(MathExp(10000.0)); // inf, NaN
PRT(MathLog(M_E)); // 1.0
PRT(MathLog(10000.0)); // 9.210340371976184
PRT(MathLog(0.5)); // -0.6931471805599453
PRT(MathLog(0.0)); // -inf, NaN
PRT(MathLog(-0.5)); // -nan(ind)
PRT(Log2(128)); // 7
PRT(MathLog10(10.0)); // 1.0
PRT(MathLog10(10000.0)); // 4.0
PRT(MathExpm1(0.1)); // 0.1051709180756476
PRT(MathLog1p(0.1)); // 0.09531017980432487
}
//+------------------------------------------------------------------+