mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-20 11:54:02 +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'.
67 lines
2.2 KiB
Mathematica
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).
|
|
|
|
%---------------------------------------------------------------------------%
|
|
%---------------------------------------------------------------------------%
|