Abstract Data TypesAn Example Package Body
PACKAGE BODY complex_type IS
FUNCTION "+" (a, b : complex) RETURN complex IS
FUNCTION "-" (a, b : complex) RETURN complex IS
FUNCTION "*" (a, b : complex) RETURN complex IS
t(re) := a(re) * b(re) - a(im) * b(im);
t(im) := a(re) * b(im) + b(re) * a(im);
FUNCTION "/" (a, b : complex) RETURN complex IS
t(re) := a(re) * b(re) + a(im) * b(im);
t(im) := b(re) * a(im) - a(re) * b(im);
i := b(re)**2 + b(im)**2;
Notes:
This is the package body showing the implementation of the standard operators on the complex type.