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

67 lines
2.2 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: float_complex.m.
% Main author: fjh.
% Stability: medium.
%
% This module provides binary operators on (float, complex).
%
% See also:
% complex.m, float.m, complex_float.m.
%
%---------------------------------------------------------------------------%
:- module complex_numbers:float_complex.
:- interface.
:- import_module float, complex_numbers:complex.
% addition
:- func float + complex = complex.
:- mode in + in = uo is det.
:- mode uo + in = in is det.
:- mode in + uo = in is det.
% subtraction
:- func float - complex = complex.
:- mode in - in = uo is det.
:- mode uo - in = in is det.
:- mode in - uo = in is det.
% multiplication
:- func float * complex = complex.
:- mode in * in = uo is det.
:- mode uo * in = in is det.
:- mode in * uo = in is det.
% division
:- func float / complex = complex.
:- mode in / in = uo is det.
:- mode uo / in = in is det.
:- mode in / uo = in is det.
%---------------------------------------------------------------------------%
:- implementation.
:- import_module complex_numbers:complex_float.
XR + cmplx(YR, YI) = cmplx(XR + YR, + XI).
XR - cmplx(YR, YI) = cmplx(XR - YR, - YI).
XR * cmplx(YR, YI) = cmplx(XR * YR, XR * YI).
XR / cmplx(YR, YI) = cmplx(XR * YR / Div, - XR * YI / Div) :-
Div = YR * YR + YI * YI.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
% Division of float / 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).
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%