mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 20:33:55 +00:00
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'.
63 lines
2.1 KiB
Mathematica
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).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|