RosettaCodeData/Task/Arithmetic-Complex/ALGOL-68/arithmetic-complex.alg

30 lines
583 B
Text
Raw Permalink Normal View History

2025-06-11 20:16:52 -04:00
BEGIN
2023-07-01 11:58:00 -04:00
PROC compl operations = VOID: (
2025-06-11 20:16:52 -04:00
COMPL a = 1.0 I 1.0;
COMPL b = 3.14159 I 1.2;
2023-07-01 11:58:00 -04:00
2025-06-11 20:16:52 -04:00
COMPL c;
2023-07-01 11:58:00 -04:00
2025-06-11 20:16:52 -04:00
PROC show compl = ( STRING legend, COMPL v )VOID:
print( ( legend, fixed( re OF v, -8, 5 ), " I ", fixed( im OF v, -8, 5 ), newline ) );
show compl(" a=",a);
show compl(" b=",b);
2023-07-01 11:58:00 -04:00
# addition #
c := a + b;
2025-06-11 20:16:52 -04:00
show compl("a+b=",c);
2023-07-01 11:58:00 -04:00
# multiplication #
c := a * b;
2025-06-11 20:16:52 -04:00
show compl("a*b=",c);
2023-07-01 11:58:00 -04:00
# inversion #
c := 1.0 / a;
2025-06-11 20:16:52 -04:00
show compl("1/c=",c);
2023-07-01 11:58:00 -04:00
# negation #
c := -a;
2025-06-11 20:16:52 -04:00
show compl(" -a=",c)
2023-07-01 11:58:00 -04:00
);
compl operations
2025-06-11 20:16:52 -04:00
END