MQL5Book/Scripts/p4/MathMod.mq5

23 lines
1,020 B
MQL5
Raw Permalink Normal View History

2025-05-30 16:09:41 +02:00
//+------------------------------------------------------------------+
//| MathMod.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#define PRT(A) Print(#A, "=", (A))
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
// 10.0 % 3.0; // '%' - illegal operation use
PRT(MathMod(10.0, 3)); // 1.0
PRT(MathMod(10.0, 3.5)); // 3.0
PRT(MathMod(10.0, 3.49)); // 3.02
PRT(MathMod(10.0, M_PI)); // 0.5752220392306207
PRT(MathMod(10.0, -1.5)); // 1.0, sign is gone
PRT(MathMod(-10.0, -1.5)); // -1.0
}
//+------------------------------------------------------------------+