Files
mercury/extras/complex_numbers/imag_complex.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

63 lines
2.1 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_complex.m.
% Main author: fjh.
% Stability: medium.
%
% This module provides binary operators on (imag, complex).
%
% See also:
% complex.m, imag.m, complex_imag.m.
%
%---------------------------------------------------------------------------%
:- module complex_numbers:imag_complex.
:- interface.
:- import_module complex_numbers:imag, complex_numbers:complex.
% addition
:- func imag + complex = complex.
:- mode in + in = uo is det.
:- mode uo + in = in is semidet.
:- mode in + uo = in is det.
% subtraction
:- func imag - complex = complex.
:- mode in - in = uo is det.
:- mode uo - in = in is semidet.
:- mode in - uo = in is det.
% multiplication
:- func imag * complex = complex.
:- mode in * in = uo is det.
% division
:- func imag / complex = complex.
:- mode in / in = uo is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module float.
im(XI) + cmplx(YR, YI) = cmplx(0.0 + YR, XI + YI).
im(XI) - cmplx(YR, YI) = cmplx(0.0 - YR, XI - YI).
im(XI) * cmplx(YR, YI) = cmplx(-XI * YI, XI * YR).
im(XI) / cmplx(YR, YI) = cmplx((XI * YI) / Div, (XI * YR) / Div) :-
Div = (YR * YR + YI * YI).
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
% Division of imag / complex formula obtained by simplifying this one:
% cmplx(Xr, Xi) / cmplx(Yr, Yi) =
% cmplx((Xr * Yr + Xi * Yi) / Div, (Xi * Yr - Xr * Yi) / Div) :-
% Div = (Yr * Yr + Yi * Yi).
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%