MQL5Book/Scripts/p4/Complex.mq5

42 lines
1.2 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 16:09:41 +02:00
//+------------------------------------------------------------------+
//| Complex.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property script_show_inputs
#include "..\..\Include\PRTF.mqh"
input double r = 1;
input double i = 2;
complex c = {r, i};
complex mirror(const complex z)
{
complex result = {z.imag, z.real}; // swap real and imaginary parts
return result;
}
complex square(const complex z)
{
return (z * z);
}
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
PRTF(c);
PRTF(square(c));
PRTF(square(mirror(c)));
}
//+------------------------------------------------------------------+
/*
c=(1,2) / ok
square(c)=(-3,4) / ok
square(mirror(c))=(3,4) / ok
*/
//+------------------------------------------------------------------+