Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
94
Task/Arithmetic-Complex/Zonnon/arithmetic-complex.zonnon
Normal file
94
Task/Arithmetic-Complex/Zonnon/arithmetic-complex.zonnon
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
module Numbers;
|
||||
type
|
||||
{public,immutable}
|
||||
Complex = record
|
||||
re,im: real;
|
||||
end Complex;
|
||||
|
||||
operator {public} "+" (a,b: Complex): Complex;
|
||||
var
|
||||
r: Complex;
|
||||
begin
|
||||
r.re := a.re + b.re;
|
||||
r.im := a.im + b.im;
|
||||
return r
|
||||
end "+";
|
||||
|
||||
operator {public} "-" (a,b: Complex): Complex;
|
||||
var
|
||||
r: Complex;
|
||||
begin
|
||||
r.re := a.re - b.re;
|
||||
r.im := a.im - b.im;
|
||||
return r
|
||||
end "-";
|
||||
|
||||
operator {public} "*" (a,b: Complex): Complex;
|
||||
var
|
||||
r: Complex;
|
||||
begin
|
||||
r.re := a.re*b.re - a.im*b.im;
|
||||
r.im := a.re*b.im + a.im*b.re;
|
||||
return r
|
||||
end "*";
|
||||
|
||||
operator {public} "/" (a,b: Complex): Complex;
|
||||
var
|
||||
r: Complex;
|
||||
d: real;
|
||||
begin
|
||||
d := b.re * b.re + b.im * b.im;
|
||||
r.re := (a.re * b.re + a.im * b.im)/d;
|
||||
r.im := (a.im * b.re - a.re * b.im)/d;
|
||||
return r
|
||||
end "/";
|
||||
|
||||
operator {public} "-" (a: Complex): Complex;
|
||||
begin
|
||||
a.im := -1 * a.im;
|
||||
return a
|
||||
end "-";
|
||||
|
||||
operator {public} "~" (a: Complex): Complex;
|
||||
var
|
||||
d: real;
|
||||
c: Complex;
|
||||
begin
|
||||
d := a.re * a.re + a.im * a.im;
|
||||
c.re := a.re/d;
|
||||
c.im := (-1.0 * a.im)/d;
|
||||
return c
|
||||
end "~";
|
||||
|
||||
end Numbers.
|
||||
|
||||
|
||||
module Main;
|
||||
import Numbers;
|
||||
|
||||
var
|
||||
a,b,c: Numbers.Complex;
|
||||
|
||||
procedure Writeln(c: Numbers.Complex);
|
||||
begin
|
||||
writeln("(",c.re:4:2,";",c.im:4:2,"i)");
|
||||
end Writeln;
|
||||
|
||||
procedure NewComplex(x,y: real): Numbers.Complex;
|
||||
var
|
||||
r: Numbers.Complex;
|
||||
begin
|
||||
r.re := x;r.im := y;
|
||||
return r
|
||||
end NewComplex;
|
||||
|
||||
begin
|
||||
a := NewComplex(1.5,3.0);
|
||||
b := NewComplex(1.0,1.0);
|
||||
Writeln(a + b);
|
||||
Writeln(a - b);
|
||||
Writeln(a * b);
|
||||
Writeln(a / b);
|
||||
Writeln(-a);
|
||||
Writeln(~b);
|
||||
end Main.
|
||||
Loading…
Add table
Add a link
Reference in a new issue