Files
mercury/extras/complex_numbers/imag.m
Fergus Henderson d23f11ac33 Use sub-modules to package up the modules in extras/complex_numbers
Estimated hours taken: 0.75

Use sub-modules to package up the modules in extras/complex_numbers
into a single module.

extras/complex_numbers/complex_lib.m:
extras/complex_numbers/complex_numbers.m:
	Rename complex_lib.m as complex_numbers.m,
	and modify it to use sub-modules.

extras/complex_numbers/*.m:
extras/complex_numbers/tests/complex_test.m:
extras/complex_numbers/samples/fft.m:
	Add `complex_numbers:' to all of the `:- module'
	and `:- import_module' declarations.

extras/complex_numbers/Mmakefile:
extras/complex_numbers/tests/Mmakefile:
extras/complex_numbers/samples/Mmakefile:
	Modify to reflect the renaming from `complex_lib' to
	`complex_numbers'.
1998-05-29 09:08:43 +00:00

86 lines
2.4 KiB
Mathematica

%---------------------------------------------------------------------------%
% Copyright (C) 1997-1998 The University of Melbourne.
% This file may only be copied under the terms of the GNU Library General
% Public License - see the file COPYING.LIB in the Mercury distribution.
%---------------------------------------------------------------------------%
%
% File: imag.m.
% Main author: fjh.
% Stability: medium.
%
% Imaginary numbers.
%
% There are several reasons for supporting a separate type for imaginary
% numbers rather than just treating them as a special case of complex
% numbers. It is sometimes more convenient, and can be slightly more
% efficient. But perhaps the most important reason is to get correct
% handling of infinity and not-a-number on platforms that support IEEE
% floating point.
%
% Note that the overloaded versions of the binary operators which
% provide mixed type arithmetic are defined in different modules.
%
% See also:
% float.m, imag_float.m, float_imag.m,
% complex.m, imag_complex.m, complex_imag.m.
%
%---------------------------------------------------------------------------%
:- module complex_numbers:imag.
:- interface.
:- import_module float.
:- type imag ---> im(float).
:- func i = imag. % i = sqrt(-1)
:- func j = imag. % another name for `i'
% addition
:- func imag + imag = imag.
:- mode in + in = uo is det.
:- mode uo + in = in is det.
:- mode in + uo = in is det.
% subtraction
:- func imag - imag = imag.
:- mode in - in = uo is det.
:- mode uo - in = in is det.
:- mode in - uo = in is det.
% multiplication
:- func imag * imag = float.
:- mode in * in = uo is det.
:- mode uo * in = in is det.
:- mode in * uo = in is det.
% division
:- func imag / imag = float.
:- mode in / in = uo is det.
:- mode uo / in = in is det.
:- mode in / uo = in is det.
% unary plus
:- func + imag = imag.
:- mode + in = uo is det.
% unary minus
:- func - imag = imag.
:- mode - in = uo is det.
%---------------------------------------------------------------------------%
:- implementation.
i = im(1.0).
j = i.
+im(X) = im(X + 0.0).
-im(X) = im(-X).
im(X) + im(Y) = im(X + Y).
im(X) - im(Y) = im(X - Y).
im(X) * im(Y) = 0.0 - X * Y.
im(X) / im(Y) = X / Y.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%