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'.
68 lines
2.0 KiB
Mathematica
68 lines
2.0 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: complex_float.m.
|
|
% Main author: fjh.
|
|
% Stability: medium.
|
|
%
|
|
% This module provides binary operators on (complex, float).
|
|
%
|
|
% See also:
|
|
% complex, float, complex_float.
|
|
%
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- module complex_numbers:complex_float.
|
|
:- interface.
|
|
:- import_module complex_numbers:complex, float.
|
|
|
|
% addition
|
|
:- func complex + float = complex.
|
|
:- mode in + in = uo is det.
|
|
:- mode uo + in = in is det.
|
|
:- mode in + uo = in is det.
|
|
|
|
% subtraction
|
|
:- func complex - float = complex.
|
|
:- mode in - in = uo is det.
|
|
:- mode uo - in = in is det.
|
|
:- mode in - uo = in is det.
|
|
|
|
% multiplication
|
|
:- func complex * float = complex.
|
|
:- mode in * in = uo is det.
|
|
:- mode uo * in = in is det.
|
|
:- mode in * uo = in is det.
|
|
|
|
% division
|
|
:- func complex / float = complex.
|
|
:- mode in / in = uo is det.
|
|
:- mode uo / in = in is det.
|
|
:- mode in / uo = in is det.
|
|
|
|
% exponentiation
|
|
:- func pow(complex, float) = complex.
|
|
:- mode pow(in, in) = out is det.
|
|
|
|
%---------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
:- import_module complex_numbers:complex_float.
|
|
|
|
cmplx(XR, XI) + YR = cmplx(XR + YR, XI).
|
|
cmplx(XR, XI) - YR = cmplx(XR - YR, XI).
|
|
cmplx(XR, XI) * YR = cmplx(XR * YR, XI * YR).
|
|
cmplx(XR, XI) / YR = cmplx(XR / YR, XI / YR).
|
|
|
|
pow(cmplx(Re0, Im0), P) = cmplx(Re, Im) :-
|
|
cartesian_to_polar(Re0, Im0, L0, Th0),
|
|
L = pow(L0, P),
|
|
Th = Th0 * P,
|
|
polar_to_cartesian(L, Th, Re, Im).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|