| # CMATH Version 3 ## for C/C++ and for Pascal/Delphi
OptiCode Dr. Martin Sander Software Development Steinachstr. 9A D-69198 Schriesheim Germany http://www.optivec.com e-mail: support@optivec.com or sales@optivec.com |

CMATH is available both separately and as a part of OptiVec. If you ordered or downloaded CMATH alone, please disregard all references to OptiVec in this documentation.
If you got CMATH as a part of OptiVec, you may wish to refer to HANDBOOK.HTM for a description of the basic principles of the OptiVec libraries and an overview over VectorLib, the first part of OptiVec. The second part, MatrixLib is described in MATRIX.HTM.
Chapter 1.2 of this file contains the licence terms for the Shareware version, Chapter 1.3 for the Registered version.
OptiCode™ and OptiVec™ are trademarks of Dr. Martin Sander Software Dev. Other brand and product names mentioned in this handbook for identification purposes are trademarks or registered trademarks of their respective holders.

| German-speaking users: Um die Kosten für das Herunterladen der Shareware-Version über das Internet für alle so gering wie möglich zu halten, enthält diese nur die englische Dokumentation. Sie finden die deutsche Beschreibung separat unter http://www.optivec.com/download/CMDOCD.ZIP.

# Contents

1. Introduction
1.1 What is CMATH ?
1.1.1 C/C++ Specifics
1.1.2 Pascal/Delphi Specifics
1.2 Licence Terms for the Shareware Version
1.3 Registered Versions
1.3.1 Registered Versions: Ordering
1.3.2 License Terms for the Registered Versions
1.4 Getting Started
2. Overview over the Functions of CMATH
2.1 Initialization of Complex Numbers
2.2 Data-Type Interconversions
2.3 Basic Complex Operations
2.4 Arithmetic Operations
2.5 Mathematical Functions
3. Error Handling
3.1 General Error Handling of Complex Functions
3.1.1 C/C++ Specifics
3.1.2 Pascal/Delphi Specifics
3.2 Advanced Error Handling: Writing Messages into a File
4. Syntax Reference
4.1 Plain-C, Pascal/Delphi Functions
4.2 Overloaded C++ Functions

#

1. Introduction

## 1.1 What is CMATH ?

CMATH is a comprehensive library for complex-number arithmetics and mathematics, both in cartesian and in polar coordinates. All functions may alternatively be called from classic C and Pascal/Delphi with type-specific function names (like cf_sin, cd_exp, pe_sqrt), or from C++ with overloaded function names and operators (like sin, exp, sqrt, operator +). As far as possible, all functions have the same names in the Pascal/Delphi version as in the plain-C version.

Superior speed, accuracy and safety are achieved through the implementation in Assembly language (as opposed to the compiled or inline code of available complex C++ class libraries). Only for the most simple tasks, alternative inline C++ functions are used in the C++ version.

The implementation was guided by the following rules:

1. Without any compromise, top priority is always given to the mathematically correct result, with the accuracy demanded for the respective data type. Especially for complex functions, this necessitates a very thorough treatment of many different situations. To this end, the various cases have to be distinguished with pedantic care.
2. Mathematical functions must be "safe" under all circumstances. They may for no reason simply crash, but have to perform a decent error treatment. This is true even - and perhaps especially - for seemingly nonsense arguments, with the single exception of the non-numbers INF and NAN, which occur themselves only as a result of serious errors in other functions.
3. By all possible means, greatest execution speed must be attained. (After all, you did not buy your fast computer for nothing!)
4. The program code has to be as compact as possible. However, in case of conflicts, faster execution speed is always given priority over smaller code size.

Having a look into other available complex class libraries, you will immediately discover the differences between our approach and theirs. Often the mathematical functions are implemented by simply writing down the textbook formula. This yields relatively compact source code. But, due to round-off error of intermediate results, the final results returned by these functions are sometimes very inaccurate or even completely wrong. Moreover, they may lead to unhandled floating-point errors (this means: program crash!). Unnecessary to mention that the code thus generated is rather slow.

This documentation describes the CMATH implementations for

- Borland C++ (Version 3.0 or higher, including all versions of Borland C++ Builder) for DOS, Windows 3.x or 32-bit Windows. The library for the memory model FLAT for Windows95/98/2000/NT requires Borland C++, version 4.0 or higher.
- Microsoft Visual C++ (Version 5.0 or higher) for Windows95/98/2000/NT on PC platforms.
- Borland Delphi 4 or higher on 32-bit Windows
- Borland (Turbo) Pascal 7.0 for DOS

Please note that only the "outside appearance" and thus the documentation is the same for these different compilers. The libraries themselves are compiler-specific; each library can be used only with one compiler and, in the case of C/C++, with one memory model or one target:

1. Shareware version for Borland C++:
   Depending on your choice when ordering or downloading, you have got either of the following three library versions:
   - Memory model FLAT for Windows95/98/NT, statically linked runtime library
   - LARGE for DOS, or
   - LARGE for Windows 3.x.
   All of them require, at least, a 386 computer equipped with a 387 coprocessor. This means: no emulation, no 486SX, but preferably 486DX, Pentium or higher.

2. Registered version for Borland C++:
   The full (registered) version for Borland C++ contains libraries for all memory models of DOS, 16-bit Windows and 32-bit Windows. These libraries, in turn, are shipped in four versions: one for P6 (Pentium III or higher) computers, the second for 486DX and Pentium, the third for 386 with 387, and – still available – the fourth for 286 with or without coprocessor, i.e. with emulation. The P6 version can only be used with BC++ 5.x, BCB 5 or higher, but not with BCB 1-4, because the linker shipped with the latter BCB versions does not correctly link P6 code.

3. Microsoft Visual C++:
   The Shareware version has 486DX/Pentium libraries for "single-thread debug" and "multi-thread debug". The full (registered) version for Microsoft Visual C++ contains additional libraries for "multi-thread DLL debug" and the three corresponding release libraries. There is no actual debug information enclosed in the OptiVec "debug" libraries, but they have to be used with the debug libraries of Visual C++. In addition, libraries optimized for Pentium III or higher are included in the full version.

4. Borland Delphi: The Shareware version requires, at least, a 386 computer equipped with a 387 coprocessor. This means: no emulation, no 486SX, but preferrably 486DX, Pentium or higher. The Registered version has separately optimized libraries for 486/Pentium, and for 386+387.

5. Borland Pascal 7.0: The Shareware version is for the real-mode DOS target and requires, at least, a 386 computer equipped with a 387 coprocessor. The registered version of OptiVec for Borland Pascal has separate units for 486/Pentium, 386+387, and 286, both for real-mode and protected-mode DOS.

Back to Table of Contents

### 1.1.1 C/C++ Specifics

The complex C++ classes and the C structs fComplex etc. are binary compatible with each other. This point may become important for large projects with mixed C and C++ modules. Existing C++ code which uses the complex class library of Borland C++, contained in <complex.h>, can be left unchanged, because the CMATH functions and data types are also binary compatible with those of <complex.h>. The single exception is the member function polar, which had to be replaced by magargtoc, as the word "polar" now denotes the complex classes in polar coordinates.

Here is a detailed description of how to switch from the complex classes of Borland C++ to the new implementation given by CMATH:

1. In C++ modules, replace the statement
   #include <complex.h>
   by the statement
   #include <newcplx.h>
   Then, the following six complex classes are defined:
   class complex<float>, class complex<double>, class complex<long double>, class polar<float>, class polar<double>, and class polar<long double>.

   The data types fComplex, dComplex, eComplex, fPolar, dPolar, and ePolar are defined as synonyms for these classes.
   In order to avoid the letter "L" (which is already over-used by long and unsigned long, extended is used as a synonym for long double in the Borland C++ version of CMATH. In the MSVC version, it is a synonym for double, as MSVC does not support 80-bit IEEE reals. Consequently, the complex data types of extended precision are named eComplex and ePolar. Thereby, the way is held open for a future inclusion of whole-number complex types into CMATH. Then, liComplex and ulComplex shall denote the complex types consisting of long int and unsigned long parts, respectively.

2. If you prefer to have the "classic" class complex of older releases of Borland C++, you have to declare
   #define CMATH_CLASSIC_COMPLEX
   before (!) including <newcplx.h>.
   In this case, only the class complex will be defined and gets the synonym dComplex. Here you will have no access to the complex-number functions of float and of extended precision, and all functions in polar coordinates are unavailable as well.
3. For plain-C modules, you cannot include <newcplx.h>. Rather, please declare
   #include <cmath.h>
   If you are using only one level of floating-point precision, you may wish to include only one of the type-specific include-files: <cfmath.h>, <cdmath.h>, or <cemath.h>, respectively.
   The plain-C implementation of CMATH is based upon the following definitions of the complex data types:
   typedef struct { float Re, Im; } fComplex;
   typedef struct { double Re, Im; } dComplex;
   typedef struct { extended Re, Im; } eComplex;
   typedef struct { float Mag, Arg; } fPolar;
   typedef struct { double Mag, Arg; } dPolar;
   typedef struct { extended Mag, Arg; } ePolar;
   As described above, the data type extended is used as a synonym for long double (Borland C++ version) or double (MSVC version).
4. Replace calls to the complex member function polar by calls to magargtoc.
5. The constituent parts of the C++ classes are declared as public (in contrast to Borland C++ !). They are named "Re" and "Im" in the cartesian classes, and "Mag" and "Arg" in the polar classes. This allows to access them as z.Re, z.Im, p.Mag, or p.Arg in C++ modules as well as in plain-C modules.
6. For time-critical applications, we recommend to use the C rather than the C++ version of CMATH, as C/C++ compilers handle structs much more efficiently than classes. To use the C version with your C++ modules, please note the following points:
   - include <cmath.h> instead of <newcplx.h>
   - for initialization, assign the real/imaginary or Mag/Arg parts directly (e.g., z.Re = 3; z.Im = 5; ) or use the functions fcplx, dcplx, ecplx, fpolr, dpolr, epolr. The constructors complex(), fComplex(), polar(), fPolar(), etc. are not available.
   - if you do a C++ compile on modules with <cmath.h> included, you have the choice between calling CMATH functions by their type-specific names (like cf_sin, cd_exp), or by their overloaded C++ names (e.g., sin, exp). On some occasions, you might be forced to use the type-specific names in order to resolve ambiguities.

Back to Table of Contents

### 1.1.2 Pascal/Delphi Specifics

The CMATH-Pascal data types are binary compatible with those of the C/C++ versions. The function names are also the same as in the plain-C version. The syntax, however, is somewhat different, as C supports complex numbers (defined as structs) as return values, whereas Pascal does not allow records to be returned by a function. Instead, they are passed as var arguments to the complex functions.

CMATH for Pascal/Delphi defines six complex data types:
type fComplex = record Re, Im: Single; end;
type dComplex = record Re, Im: Double; end;
type eComplex = record Re, Im: Extended; end;
type fPolar = record Mag, Arg: Float; end;
type dPolar = record Mag, Arg: Double; end;
type ePolar = record Mag, Arg: Extended; end;

The reason why the single-precision type gets the name fComplex instead of sComplex is that the letter "s" is already over-used by ShortInt and SmallInt in Pascal. Therefore, this name is derived from the C/C++ analogue of Single, which is float.

Back to Table of Contents

## 1.2 Licence Terms for the Shareware Version

In case you got CMATH as a part of OptiVec, the CMATH licence is included in the OptiVec licence. Otherwise, the following licence terms apply to the Shareware version of CMATH. For the licence terms of the Registered version, please see paragraph 1.3.

This is the Shareware version of CMATH ("SOFTWARE").
It may be used under the following licence terms:

1. You may test the SOFTWARE free of charge for a period of up to 90 days on one computer.
2. Applications, created with the Shareware version of this SOFTWARE, will run only on the same computer on which this SOFTWARE has been installed. They cannot and may not be distributed to others. After the end of the trial period, they will cease functioning.
3. If you want to continue using this SOFTWARE after testing, and/or if you wish to distribute programs containing functions of this SOFTWARE, you have to purchase the registered version (see chapter 1.3).
4. This SOFTWARE is provided on an "as is" basis. Any explicit or implicit warranties for the SOFTWARE are excluded.
5. Despite thorough testing of the SOFTWARE, errors and bugs cannot be excluded with certainty. No claims as to merchantability or fitness for a particular purpose are made.
6. You may not use the SOFTWARE in any environment or situation where personal injury or excessive damage to anyone's property (including your own) could arise from malfunctioning of the SOFTWARE.
7. You may not decompile, disassemble, or otherwise reverse engineer the SOFTWARE into a machine-readable form. You may, however, inspect the functions it contains by means of debuggers like those included in the Borland and Microsoft compilers.

Copyright for the SOFTWARE and its documentation © 1996-2003 OptiCode - Dr. Martin Sander Software Dev.
All rights reserved, including those of translation into foreign languages.

Back to Table of Contents

## 1.3 Registered Versions

## 1.3.1 Registered Versions: Ordering

In order to make this product affordable also for those who will not themselves make money using it, we offer an educational edition at a strongly reduced rate, in addition to the full commercial edition. The contents of these two editions is identical. The only difference lies in the restrictions of use: The educational edition may not be used for commercial / business / government purposes, but is restricted to private and educational use.

Purchasing the full (registered) version gives you the right to use it on as many computers at a time as the number of units you bought.

The right to distribute applications employing functions of CMATH is included in the commercial-version licence. No run-time licence are needed for your customers! Corporate site and world-wide licences are available upon request.

The full versions (both the commercial and the educational editions) of CMATH

- support all memory models of Windows95/98, NT, 3.x, and DOS (Borland C++)
- single-thread, multi-thread, multi-thread DLL debug and release (Microsoft Visual C++)
- Delphi 4 through 7 (Borland Delphi)
- the real-mode DOS and DPMI targets (Borland Pascal 7.0)
- Borland C++ and Pascal only:
  have individually optimized libraries for each degree of processor backward-compatibility:
  P6 (requiring Pentium III; C++ only)
  486DX/Pentium+ (optimized for Pentium II)
  386+ (387 coprocessor required)
  286+ (no coprocessor required; C/C++ only).
- (C/C++ versions only:) come with printed documentation (which, however, is updated much less frequently than the electronic documentation).
- entitle you to two years of free updates (by downloading from our web site)
- can be ordered the following ways:
  a) International orders (credit-card or US cheque) by Internet, mail, FAX, or phone
  b) Orders within the European Union (pre-paid or upon invoice)

### a) International Orders: Pricing

#### CMATH for Borland C/C++, Microsoft Visual C++, or Borland Delphi
(CD-ROM, manual in English)

$ 39 for 1 unit of the educational edition
$ 60 for 1 unit of the commercial edition
$ 200 for 5 units (only through SWREG)
$ 350 for 10 units (only through SWREG)
Add $ 5 for S&H (postal) and applicable VAT.

#### CMATH for Borland (Turbo) Pascal

$ 25 for 1 unit + $ 5 for S&H

### International: Ordering Options

For your protection, we handle credit-card orders through two specialized secure services:

SWREG:
When ordering online through SWREG, please use the product-specific links below:
CMATH for C/C++
CMATH for Pascal/Delphi
Please choose the exact version and delivery options in the simple pulldown menu on the respective page.

ShareIt: When ordering online through ShareIt, please use the product-specific links below:
CMATH for Borland C/C++
CMATH for Microsoft Visual C++
CMATH for Borland Delphi
CMATH for Borland (Turbo) Pascal

You may also order by e-mail to register@shareit.com.
US customers can also contact ShareIt! by telephone 1-724-850-8186 or FAX 1-724-850-8189 (only for orders, please).
Note the program No.:

| commercial | educational
CMATH for Borland C/C++ | 101353 | 102655
CMATH for Microsoft Visual C++ | 103422 | 103441
CMATH for Borland (Turbo) Pascal | 103424
CMATH for Borland Delphi | 103844 | 103860

### b) Orders in the European Union

If you can pay in Euro and order directly from the author, the pricing is

#### CMATH for Borland C/C++, Microsoft Visual C++, or Borland Delphi
(CD-ROM, manual in English)

EUR 39 for 1 unit of the educational edition
EUR 59 for 1 unit of the commercial edition
EUR 199 for 5 units
EUR 349 for 10 units
(incl. 16% German VAT, plus EUR 5,- handling charge).

#### CMATH for Borland (Turbo) Pascal

EUR 19 for 1 unit + EUR 5 for S&H (incl. 16% German VAT)

If you have a European VAT ID, or if you order from outside the European Union, you are exempt from German VAT, and it will be deduced from your bill, but you may have to pay your local VAT and/or import duties according to local laws.

Please send a print-out of this order form to

OptiCode - Dr. Martin Sander Software Dev.
Steinachstr. 9A
D-69198 Schriesheim
Germany

FAX +49 - 6203 - 92 53 96

For any other questions related to ordering CMATH, please contact us at: sales@optivec.com

Back to Table of Contents

### 1.3.2 License Terms for the Registered version

In case you got CMATH as a part of OptiVec, the CMATH licence is included in the OptiVec licence. Otherwise, these are the license terms valid for you, if you got this file with the registered version of CMATH, :

This is a single copy license for CMATH ("SOFTWARE"), granted by OptiCode - Dr. Martin Sander Software Development ("OptiCode").

The SOFTWARE in this package is licensed to you as the user. It is not sold. The term "user" means a programmer who links binary code of this SOFTWARE into his own applications. Those people using, in turn, his applications without the need of installing this SOFTWARE themselves, do not need any runtime license for the SOFTWARE. The right to distribute applications containing code of this SOFTWARE is included in the license fee for the commercial version.

Once you have paid the required license fee, you may use the SOFTWARE for as long as you like, provided you do not violate the copyright and if you observe the following rules:

1. You may use the SOFTWARE on any computer for which it is designed, as long as not more than one person uses it at any time.
2. You may make backup copies of the SOFTWARE for your personal use. You may only transfer the SOFTWARE to somebody else if you transfer the original and all copies, retaining no copies for yourself. You may not lease or rent the SOFTWARE to others.
3. You may not decompile, disassemble, or otherwise reverse engineer the SOFTWARE into a machine-readable form. You may, however, inspect the functions contained in this SOFTWARE by means of debuggers like those included in the Borland and Microsoft compilers.
4. If you payed the reduced licence fee for the "educational version" rather than the full rate for the "commercial version", the use of this SOFTWARE is restricted to private and educational purposes. In this case, you may not use the SOFTWARE for commercial purposes or for government purposes other than education.
   Applications using functions of this SOFTWARE may be freely distributed (i.e. without any run-time licence) only if created with the "commercial edition", and on condition that the functions of this SOFTWARE are permanently linked into a program etc., but do not appear as a library to the user of that application.
5. You may not use the SOFTWARE in any environment or situation where personal injury or excessive damage to anyone's property (including your own) could arise from malfunctioning of the SOFTWARE.
6. OptiCode's liability is limited by the enclosed Limited Warranty. In no case shall OptiCode's liability exceed the license paid for the right to use the SOFTWARE.

Limited Warranty for the Registered version

1. OptiCode warrants that the magnetic or optic media on which the SOFTWARE is recorded are free from defects in materials and workmanship under normal use. The SOFTWARE itself will perform substantially in accordance with the specifications set forth in the documentation.
2. The above express warranties are made for a period of six months from the date the SOFTWARE is delivered to you as the first user.
3. Any magnetic/optic or printed media from this package proving defective in materials or workmanship will be replaced on an exchange basis.
4. Great care has been taken to ensure that the SOFTWARE operates in accordance with the specifications as described in the documentation. However, it is not guaranteed that this SOFTWARE will operate completely free of errors or that the documentation is free of errors.
5. Any implied warranties including any warranties of merchantability or of fitness for a particular purpose are limited to the terms of the above express warranties.
6. OptiCode shall not in any case be liable for special, incidental, consequential, indirect or other damages arising from any breach of these warranties or of the license conditions, even if he has been notified of the possibility of such damages.

Copyright for the SOFTWARE and its documentation © 1996-2003 OptiCode - Dr. Martin Sander Software Development. All rights reserved.

Back to Table of Contents

## 1.4 Getting Started

If you got CMATH as a part of OptiVec, you should read chapter 1.4 of HANDBOOK.HTM instead of the remainder of the present paragraph. If you have already read that, continue with chapter 2, or go back to the Table of Contents.

To install CMATH, please follow these steps:

1. In order to use CMATH, you need an already installed copy of your C/C++, Delphi, or Pascal compiler. Install CMATH by executing INSTALL.EXE from the root directory of the installation disk or CD-ROM. Normally, CMATH will be installed into a directory named "CMATH". This directory holds the documentation.
2. Include the CMATH lib and include (C/C++) or units (Pascal/Delphi) subdirectories into the search path.
3. a) C/C++:
   Assuming your CMATH directory is C:\CMATH, add
   C:\CMATH\LIB to the library search path and
   C:\CMATH\INCLUDE to the include-file search path of the IDE (and of the configuration file TURBOC.CFG and BCC32.CFG in case you are using Borland's command-line compilers).
   b) Pascal/Delphi, Shareware version:
   Pascal: The CMATH unit will be installed into the directory CMATH\UNITS.
   Delphi: The units (.DCU files) will be installed into the directory CMATH\LIB.
   c) Pascal/Delphi, Registered version:
   Pascal: The unit for 386+387 will be installed into the directory CMATH\UNITS.
   The additional units for 486/Pentium are contained in the file UNITS4.ZIP and are not automatically installed. If you wish to use them, manually create the subdirectory CMATH\UNITS4 and unzip the file mentioned into it.
   Delphi: The installation routine you have to execute is named after the target Delphi version: INSTALL4.EXE, INSTALL5.EXE, INSTALL6.EXE, etc.. The units (.DCU files) for 386+387 will be installed into CMATH\LIB3, those for 486/Pentium into CMATH\LIB4.
4. Choose the desired platform, target, and configuration:
   1. Borland C++:
      Choose the desired platform (DOS, Windows3.x, or Win32) and memory model. Select the required library from the following table (add the suffix .LIB) and add it to your project. The Shareware versions contain only libraries for either DOS-LARGE, Windows-LARGE, or Win32.

      Platform | Memory Model | Required Processor
      286 | 386+387 | 486DX/Pentium | Pentium III
      DOS | TINY |
      CMATHS2 | CMATHS3 | CMATHS4 | –––
      DOS | SMALL |
      CMATHS2 | CMATHS3 | CMATHS4 | –––
      DOS | MEDIUM |
      CMATHM2 | CMATHM3 | CMATHM4 | –––
      DOS | COMPACT |
      CMATHC2 | CMATHC3 | CMATHC4 | –––
      DOS | LARGE |
      CMATHL2 | CMATHL3 | CMATHL4 | –––
      DOS | HUGE |
      CMATHH2 | CMATHH3 | CMATHH4 | –––
      Windows | SMALL |
      CMATHS2W | CMATHS3W | CMATHS4W | –––
      Windows | MEDIUM |
      CMATHM2W | CMATHM3W | CMATHM4W | –––
      Windows | COMPACT |
      CMATHC2W | CMATHC3W | CMATHC4W | –––
      Windows | LARGE |
      CMATHL2W | CMATHL3W | CMATHL4W | –––
      32-bit Windows static run-time library dynamic run-time library | (FLAT) GUI or Console |
      ––– | CMATHF3W CMF3WD | CMATHF4W CMF4WD | CMATHF6W CMF6WD

   2. Visual C++: Choose the target and configuration and add the corresponding CMATH library to your project, according to the following table. Note that the Shareware version contains only libraries for single-thread debug and multi-thread debug.

      Target | Configuration | 486/Pentium library | Pentium III library
      single-thread | debug | CMVCSD.LIB | CMVCSD6.LIB
      single-thread | release | CMVCSR.LIB | CMVCSR6.LIB
      multi-thread | debug | CMVCMTD.LIB | CMVCMTD6.LIB
      multi-thread | release | CMVCMTR.LIB | CMVCMTR6.LIB
      multi-thread DLL | debug | CMVCMDD.LIB | CMVCMDD6.LIB
      multi-thread DLL | release | CMVCMDR.LIB | CMVCMDR6.LIB

      In order to allow CMATH to be used in applications both with and without MFC, it calls the Windows API only directly, not via MFC. However, if you use MFC (either as a static library or as a DLL), Visual C++ does not automatically link the import library, user32.lib. You have to explicitly do this yourself: The line, Project / Settings / Linker / Object and Library Modules must contain user32.lib. Otherwise you would get the linker error "error LNK2001: Unresolved external symbol __imp__MessageBoxA@??".
   3. Borland Pascal:
      Choose the target DOS real mode or (for the registered version only) DOS protected-mode.
   4. Borland Delphi:
      No choices are to be made at this level.
5. Declare the use of CMATH functions in your program,:
   - C/C++:
     #include <newcplx.h> (C++) or <cmath.h> (C or C++), as described above.
     If you are writing MFC or Borland C++ ObjectWindows applications, the CMATH header files should be included after the MFC or OWL header files.
   - Pascal/Delphi:
     Declare the use of CMATH units as usual with the "uses CMATH" statement.
6. Borland C/C++ 16-bit programs only:
   CMATH works with Borland (Turbo) C++, version 3.0 or higher. Since, from version 4.0 on, Borland changed the name of the error handling routine matherr (without underbar) into _matherr (with a leading underbar), any 16-bit program using CMATH has to call a macro, NEWMATHERR, which takes care of redirecting calls to _matherr, if necessary. You should place the call to NEWMATHERR into the module containing main() or OwlMain():
   #include .....
   #include <cmath.h> /* or <newcplx.h> */
   NEWMATHERR
   int main( void )
   { .......... }
   If you forget to call NEWMATHERR, you will get a linker error "Unresolved external _matherr" in the Borland C versions from 4.0 on. Inclusion of the macro NEWMATHERR is not needed for 32-bit programs.
7. Have a look into the sample program, CDEMO.CPP or CDEMO.PAS.

After these preparations, all CMATH functions are available for your programs.
Should you wish to remove CMATH from your computer, please run UNINSTAL.EXE, or simply delete the directory CMATH with its subdirectories.

Back to Table of Contents

# 2. Overview over the Functions of CMATH

In the following, it is often only the fComplex or fPolar version of a function that is explicitly mentioned. The versions for dComplex / dPolar, and eComplex / ePolar are always exactly analogous.
All functions for the languages C and Pascal/Delphi have a prefix denoting the data type on which the function works:
"cf_" or "pf_" stands for single precision (arguments and return values of the data types fComplex, fPolar, sometimes together with float),
"cd_" or "pd_" stands for double precision (arguments and return values of the data types dComplex, dPolar, sometimes together with double), whereas
"ce_" and "pe_" denote extended-precision functions.

In C++, synonyms are defined for all these functions. The synonyms do not have a prefix, since the data type information is implicitly handled by the C++ compiler. The C++ function names are always identical to those found in the complex class libraries (if the respective function exists there), with the single exception of the member function polar, which had to be replaced by magargtoc, as the name "polar" had to be reserved for the polar classes. Of course, if you wish to use the C function names in your C++ modules, you can do so by including <cmath.h> instead of <newcplx.h>.

##

2.1. Initialization of Complex Numbers

In the following, we denote the complex classes by by their short names, fComplex, fPolar, etc. In C++, you can always use the template nomenclature instead, writing "complex<float>" wherever "fComplex" is written here, and so on for all other complex types and classes.

Complex numbers are initialized by separately assigning a value to the imaginary and real parts or to the Mag and Arg parts, e.g.:
z.Re = 3.0; z.Im = 5.7;
p.Mag = 8.8; p.Arg = 3.14;
(Of course, for Pascal/Delphi, the assignment operator is written ":=").
Alternatively, the same initialization can be accomplished by the functions fcplx or fpolr:
C/C++:
z = fcplx( 3.0, 5.7 );
p = fpolr( 4.0, 0.7 );

Pascal/Delphi:
fcplx( z, 3.0, 5.7 );
fpolr( p, 3.0, 5.7 );

For double-precision complex numbers, use dcplx and dpolr, for extended-precision complex numbers, use ecplx and epolr.

##

2.2. Data-Type Interconversions

Interconversions between the various complex types are performed via the functions:

cftocd, cdtocf, cftoce, cetocf, cdtoce, cetocd | up- or down-conversion of accuracy within the cartesian-complex types
pftopd, pdtopf, pftope, petopf, pdtope, petopd | up- or down-conversion of accuracy within the polar-complex types
cftopf, cftopd, cftope, cdtopf, cdtopd, cdtope, cetopf, cetopd, cetope | conversion from cartesian into polar complex
pftocf, pftocd, pftoce, pdtocf, pdtocd, pdtoce, petocf, petocd, petoce | conversion from polar into cartesian complex

OVERFLOW errors in the course of down-conversions are silently cured: program execution is continued with the largest value possible.

C++ only: | For C++ modules, there are several overloaded constructors as an alternative to the above functions: basic forms: fComplex fComplex( float RePart, float ImPart=0 ); fComplex fComplex( dComplex ); fComplex fComplex( eComplex ); fPolar fPolar( float MagPart, float ArgPart=0 ); fPolar fPolar( dPolar ); fPolar fPolar( ePolar ); interconversion cartesian <--> polar: fComplex fComplex( fPolar ); fComplex fComplex( dPolar ); fComplex fComplex( ePolar ); fPolar fPolar( fComplex ); fPolar fPolar( dComplex ); fPolar fPolar( eComplex ); Similarly to the constructors fComplex() and fPolar(), also dComplex(), dPolar(), eComplex, and ePolar() exist in overloaded versions performing the same tasks for the classes dComplex, dPolar, eComplex, and ePolar, respectively. As described above for the C/Pascal/Delphi versions, OVERFLOW errors in the course of down-conversions are silently cured, without calling _matherr.

A special constructor for polar numbers is
fPolar pf_principal( fPolar __p );
and, for C++ only, its overloaded form for two separate real input numbers
fPolar principal( float Mag, float Arg );
These functions reduce the input Arg to the range -p < Arg <= +p. You might recall that each complex number has an infinite number of representations in polar coordinates, with the angles differing by an integer multiple of 2 p. The representation with -p < Arg <= +p is called the principal value.
Please note that these are the only polar functions reducing the output to the principal value. All others accept and return arguments whose angles may fall outside this range.

The conversion between cartesian and polar format involves transcedental functions and is, therefore, quite time-consuming. It is true that multiplications are faster in polar coordinates, whereas additions are much faster in Cartesian. The difference, however, is so much smaller than the cost of switching back and forth between the different representations, that we recommend you stay in general with the cartesian format. Only in the following cases, the conversion really makes sense:

1. You have only multiplications and related math functions (like square, sqrt, ipow). Then, you should start out with polar coordinates.
2. You have to call the complex exponential function. In this case, cf_exptop brings you into polar coordinates in a very natural manner.
3. You are in polar coordinates and have to calculate the logarithm. In this case, pf_logtoc (or similarly pf_log2toc, pf_log10toc) brings you "down" to the cartesian representation.

Zurück zum Inhaltsverzeichnis

## 2.3 Basic Complex Operations

The following basic complex operations are defined in CMATH:

cartesian C/Pascal/Delphi function | polar C/Pascal/Delphi function | overloaded C++ function | explanation
cf_conj | pf_conj | conj | complex-conjugate form
cf_neg | pf_neg | neg (or -) | negation
cf_real | pf_real | real | extraction of the real part
cf_imag | pf_imag | imag | extraction of the imaginary part
cf_magargtoc | N.A. | magargtoc | conversion of polar coordinates, entered as separate real numbers, into cartesian format
N.A. | pf_reimtop | reimtop | conversion of complex coordinates, entered as separate real numbers, into polar format
cf_abs | pf_abs | abs | absolute value (magnitude of the pointer in the complex plane; this is treated as a math function with error handling)
cf_arg | pf_arg | arg | argument (angle of the pointer in the complex plane)
cf_norm | pf_norm | norm | norm (defined here as the square of the absolute value)
N.A. | pf_principal | principal | principal value, with -p < Arg <= +p

(The double and extended-precision versions are exactly analogous to the cf_ / pf_ version)

Back to Table of Contents

## 2.4 Arithmetic Operations

Only C++: | The following set of operators is available for all of the three cartesian complex classes: + - * / += -= *= /= == != For the polar complex classes, we have: * / *= /= == != These operators exist also for "mixed" arguments, where one argument is complex, the other real and where the arguments are of different floating-point accuracies.

Since it is only the language C++, but neither plain-C nor Pascal, which allows overloaded arithmetic operators, all arithmetic operations of complex numbers are implemented additionally as functions which may be called from C/Pascal/Delphi as well as C++ modules:

Cartesian | Polar |
cf_add | N.A. | addition of two complex numbers
cf_addRe | N.A. | addition of a complex number and a real number
cf_sub | N.A. | subtraction of two complex numbers (first operand minus the second operand)
cf_subRe | N.A. | subtraction of a real number from a complex number
cf_subrRe | N.A. | subtraction of a complex number from a real number
cf_mul | pf_mul | multiplication of two complex numbers
cf_mulRe | pf_mulRe | multiplication of a complex number and a real number
cf_div | pf_div | division of two complex numbers (first operand divided by the second operand)
cf_divRe | pf_divRe | division of a complex number by a real number
cf_divrRe | pf_divrRe | division of a real number by a complex number

(similarly the double- and extended-precision versions)

The assignment operator "=" or ":=" is the only operator defined also in plain-C and Pascal/Delphi for complex numbers.

Back to Table of Contents

## 2.5 Mathematical Functions

CMATH contains all mathematical functions you would find in the complex class libraries of C++, along with several additional ones:

cartesian C/Pascal/Delphi function | polar C/Pascal/Delphi function | overloaded C++ function | formula | explanation
cf_abs | pf_abs | abs | ry = | zx | | absolute value
cf_acos | N.A. | acos | zy = acos( zx ) | arcus cosine function
cf_asin | N.A. | asin | zy = asin( zx ) | arcus sine function
cf_atan | N.A. | atan | zy = atan( zx ) | arcus tangent function
cf_cos | N.A. | cos | zy = cos( zx ) | cosine
cf_cosh | N.A. | cosh | zy = cosh( zx ) | hyperbolic cosine
cf_cubic | pf_cubic | cubic | zy = zx3 | third power
cf_exp | cf_exptop | exp | zy = exp( zx ) | exponential function
cf_inv | pf_inv | inv | zy = 1.0 / zx | inverse
cf_ipow | pf_ipow | ipow | zy = zxn | integer power
cf_ln | pf_lntoc | ln | zy = ln( zx ) | natural logarithm
cf_log | pf_logtoc | log | zy = ln( zx ) | identical to cf_ln, pf_lntoc, ln
cf_log2 | pf_log2toc | log2 | zy = lb( zx ) | binary logarithm
cf_log10 | pf_log10toc | log10 | zy = lg( zx ) | decadic logarithm
cf_pow | N.A. | pow | zy = zxzexp | arbitrary power
cf_powReBase | N.A. | pow, powReBase | zy = rzx | real base to complex power
cf_powReExpo | pf_powReExpo | pow, powReExpo | zy = zxr | real power of complex base
cf_quartic | pf_quartic | quartic | zy = zx4 | fourth power
cf_sin | N.A. | sin | zy = sin( zx ) | sine
cf_sinh | N.A. | sinh | zy = sinh( zx ) | hyperbolic sine
cf_square | pf_square | square | zy = zx2 | square
cf_sqrt | pf_sqrt | sqrt | zy = sqrt( zx ) | square root
cf_tan | N.A. | tan | zy = tan( zx ) | tangent
cf_tanh | N.A. | tanh | zy = tanh( zx ) | hyperbolic tangent

As noted above, the exponential and logarithm functions provide a natural transition between cartesian and polar coordinates. While there are exp and log functions for fComplex as argument and as return value, cf_exptop takes an fComplex argument and returns fPolar. In the opposite direction, pf_logtoc takes an fPolar argument and returns fComplex.

Back to Table of Contents

# 3. Error Handling

## 3.1 General Error Handling of Complex Functions

The error handling of complex functions follows the rules employed generally also for real-number functions and operations. For all arithmetic operations, the design of the algorithms eliminates the danger of failure due to irregular intermediate results. Overflowing or otherwise irregular final results, however, will lead to a hardware interrupt being generated and, as a consequence, to a program abort.

In contrast to the arithmetic operations, all mathematical functions and all data-type interconversions perform a tight error checking. All error messages eventually generated use the C/Pascal/Delphi name (rather than the overloaded C++ name) of the failing function.

If you got CMATH as a part of OptiVec, you should read chapter 5 of HANDBOOK.HTM rather than the present chapter.

## 3.1.1 C/C++ Specifics

All error conditions in CMATH math functions are handled via _matherr (for fComplex, fPolar, dComplex, and dPolar functions) and _matherrl (for eComplex and ePolar functions; Borland C++ only). The real or Mag part of the complex argument, causing an error is stored in e->x and the imaginary or Arg part in e->y.

### Borland C++ 16-bit programs only:

As mentioned already in chapter 2, Borland has changed the name of the error-handling function matherr (without leading underbar), used in the versions 3.x, into _matherr (with a leading underbar), from version 4.0 on.
In order to make CMATH compatible with both the older and the later versions of Borland C++, the following way of error handling was adopted:
In case of an error, all CMATH functions call primarily matherr (as in the older versions of Borland C++). A macro NEWMATHERR provides for the necessary redirection of these calls to _matherr, if a later version of Borland C++ is used. Therefore, NEWMATHERR must be called once (!) in any program using CMATH, after the inclusion of <cmath.h> or <newcplx.h>. The best place is the module containing the main(), WinMain(), or OWLMain() function, after the header:
#include <cmath.h> /* or <newcplx.h> */
#include ...
NEWMATHERR
......
main()
{ ... }

Back to Table of Contents

## 3.1.2 Pascal/Delphi Specifics

How CMATH handles floating-point errors in the complex math functions is defined by a call to V_setFPErrorHandling. A number of pre-defined constants fperrXXX is available for the construction of the desired error-handling mode:

Constant | Value | Meaning
fperrIgnore | 0 | Ignore all floating-point errors: handle them silently, do not print a message, continue program execution
fperrNoteDOMAIN | $0001 | Print a message in case of a DOMAIN error
fperrNoteSING | $0002 | Print a message in case of a SING error
fperrNoteOVERFLOW | $0003 | Print a message in case of an OVERFLOW error
fperrNoteTLOSS | $0004 | Print a message in case of a TLOSS error
fperrAbortDOMAIN | $0101 | Abort program in case of a DOMAIN error
fperrAbortSING | $0202 | Abort program in case of a SING error
fperrAbortOVERFLOW | $0303 | Abort program in case of an OVERFLOW error
fperrAbortTLOSS | $0404 | Abort program in case of a TLOSS error
fperrDefaultHandling | $0107 | Same as fperrAbortDOMAIN or fperrNoteSING or fperrNoteOVERFLOW

Example:
V_setFPErrorHandling( fperrAbortDOMAIN + fperrAbortSING + fperrAbortOVERFLOW + fperrNoteTLOSS );
In this example, program execution will be aborted (with the appropriate message) in the case of the most severe errors, DOMAIN and SING. In the case of OVERFLOW and TLOSS errors, a warning will be displayed, but program execution will be continued with default results set by the respective functions where the errors occur. The repeated occurrence of the same type of error within one and the same function will lead to only one message being generated. Subsequent errors will be treated silently.

Back to Table of Contents

## 3.2 Advanced Error Handling: Writing Messages into a File

Quite generally, the libraries shipped with compilers do not offer the programmer much control over the way error messages are printed. While this is fine in most instances, there may be situations in which you might, for example, wish the error messages not to be printed to the screen, but rather into a file, so that you could check later what has gone wrong. An additional motivation could come from the fact that, for any error occurring in a Windows program, a message box is displayed and program execution interrupted until you acknowledge having taken notice of the error.

You might wish to circumvent this. To this end, OptiVec and CMATH provide the function V_setErrorEventFile. This function needs as arguments the desired name of your event file and a switch named ScreenAndFile which decides if you wish to have error messages printed simultaneously into the file and onto the screen (ScreenAndFile = TRUE (non-zero)) or exclusively into the file (ScreenAndFile = FALSE (0)).

Example:
V_setErrorEventFile( "MyLogFil.TXT", 0 ); /* C/C++ */
V_setErrorEventFile( 'MyLogFil.TXT', FALSE ); (* Pascal/Delphi *)
Here, you will get all subsequent error messages only into your log file, MyLogFil.TXT and no messages on the screen. The default, i.e., printing error messages to the screen, is restored by V_closeErrorEventFile. (That function does not take any arguments and does not return anything.)

Note that this redirection of error messages is valid only for errors occurring in OptiVec (CMATH) routines. If you wish to do so, however, there is a way in C/C++ to extend the redirection also to the "non-OptiVec" functions: you may modify _matherr and _matherrl such that the statement
return 0;
(which signals an unresolved error) is replaced by the sequence
V_noteError( e->name, e->type ); return 1;
Thereby the task of printing the error message for unresolved errors is passed to the OptiVec function V_noteError which shall check if an error event file was defined or not and direct its output to the desired place. Keep in mind that it is the return value of _matherr which decides if an error message is printed by the default error handler of your compiler. Thus, after the call to V_noteError, the printing of the default error messages is by-passed by returning "1". (Also, do not forget that OptiVec / CMATH uses your _matherr routine to determine which errors you accept and which not!)

For example, your _matherr function (matherr - without the leading underbar - for Borland C++ 3.0 and 3.1) might look like the following one:
#include <math.h>
int _matherr( struct exception *e) /* "_exception" for MSVC */
{
if( (e->type == UNDERFLOW) || (e->type == TLOSS) ) ; /* ignore */
else /* all other errors deserve at least notice */
{
V_noteError( e->name, e->type );
if (e->type == DOMAIN) exit(1); /* really fatal */
}
return 1;
}
(Of course, if you decide to change _matherr, do not forget to change _matherrl in the same way, if you are using Borland C++!).

Zurück zum Inhaltsverzeichnis

# 4. Syntax Reference

Except for the data-type conversion functions, only the float / fComplex / fPolar syntax is given. The syntax of the functions for double and extended precisions is exactly analogous.
If you chose the "classic" class complex, this is also similar. Just replace "float" by "double" and "fComplex" by "complex". No polar functions are available in the "classic" class complex, neither do any of the type-casting operators and interconversion functions exist, if there is only one type.

Zurück zum Inhaltsverzeichnis

## 4.1 Plain-C, Pascal/Delphi Functions

For the functions of double / dComplex / dPolar and extended / eComplex / ePolar precision, the prefixes are cd_, pd_, ce_, and pe_, respectively.

float cf_abs( fComplex __z );
function cf_abs( zx:fComplex ): Single;

float pf_abs( fPolar __p );
function pf_abs( px:fPolar ): Single;

fComplex cf_acos( fComplex __z );
procedure cf_acos( var zy:fComplex; zx:fComplex );

fComplex cf_add( fComplex __x, fComplex __y );
procedure cf_add( var zz:fComplex; zx, zy:fComplex );

fComplex cf_addRe( fComplex __x, float __yRe );
procedure cf_addRe( var zz:fComplex; zx:fComplex; yRe:Single );

float cf_arg( fComplex __z );
function cf_arg( zx:fComplex ): Single;

float pf_arg( fPolar __z );
function pf_arg( px:fPolar ): Single;

fComplex cf_asin( fComplex __z );
procedure cf_asin( var zy:fComplex; zx:fComplex );

fComplex cf_atan( fComplex __z );
procedure cf_atan( var zy:fComplex; zx:fComplex );

eComplex cdtoce( dComplex __zd );
procedure cdtoce( var zy:eComplex; zx:dComplex );

fComplex cdtocf( dComplex __zd );
procedure cdtocf( var zy:fComplex; zx:dComplex );

dPolar cdtopd( dComplex __zd );
procedure cdtopd( var py:dPolar; zx:eComplex );

ePolar cdtope( dComplex __zd );
procedure cdtope( var py:ePolar; zx:eComplex );

fPolar cdtopf( dComplex __zd );
procedure cdtope( var py:fPolar; zx:eComplex );

dComplex cetocd( eComplex __ze );
procedure cetocd( var zy:dComplex; zx:eComplex );

fComplex cetocf( eComplex __ze );
procedure cetocf( var zy:fComplex; zx:eComplex );

dPolar cetopd( eComplex __ze );
procedure cetopd( var py:dPolar; zx:eComplex );

ePolar cetope( eComplex __ze );
procedure cetope( var py:ePolar; zx:eComplex );

fPolar cetopf( eComplex __ze );
procedure cetopf( var py:fPolar; zx:eComplex );

dComplex cftocd( fComplex __zf );
procedure cftocd( var zy:dComplex; zx:fComplex );

eComplex cftoce( fComplex __zf );
procedure cftoce( var zy:eComplex; zx:fComplex );

dPolar cftopd( fComplex __zf );
procedure cftopd( var py:dPolar; zx:fComplex );

ePolar cftope( fComplex __zf );
procedure cftope( var py:ePolar; zx:fComplex );

fPolar cftopf( fComplex __zf );
procedure cftopf( var py:fPolar; zx:fComplex );

fComplex cf_conj( fComplex __z );
procedure cf_conj( var zy:fComplex; zx:fComplex );

fPolar pf_conj( fPolar __p );
procedure pf_conj( var py:fPolar; px:fPolar );

fComplex cf_cos( fComplex __z );
procedure cf_cos( var zy:fComplex; zx:fComplex );

fComplex cf_cosh( fComplex __z );
procedure cf_cosh( var zy:fComplex; zx:fComplex );

fComplex cf_cubic( fComplex __z );
procedure cf_cubic( var zy:fComplex; zx:fComplex );

fPolar pf_cubic( fPolar __p );
procedure pf_cubic( var py:fPolar; px:fPolar );

fComplex cf_div( fComplex __x, fComplex __y );
procedure cf_div( var zz:fComplex; zx, zy:fComplex );

fPolar pf_div( fPolar __x, fPolar __y );
procedure pf_div( var pz:fPolar; px, py:fPolar );

fComplex cf_divRe( fComplex __x, float __yRe ); /* x / yRe */
procedure cf_divRe( var zz:fComplex; zx:fComplex; yRe:Single );

fPolar pf_divRe( fPolar __x, float __yRe ); /* x / yRe */
procedure pf_divRe( var pz:fPolar; px:fPolar; yRe:Single );

fComplex cf_divrRe( fComplex __x, float __yRe ); /* yRe / x */
procedure cf_divrRe( var zz:fComplex; zx:fComplex; yRe:Single );

fPolar pf_divrRe( fPolar __x, float __yRe ); /* yRe / x */
procedure pf_divrRe( var pz:fPolar; px:fPolar; yRe:Single );

fComplex cf_exp( fComplex __z );
procedure cf_exp( var zy:fComplex; zx:fComplex );

fPolar cf_exptop( fComplex __z );
procedure cf_exptop( var py:fPolar; zx:fComplex );

fComplex fcplx( float __ReVal, float __ImVal);
procedure fcplx( var zy:fComplex; xRe, xIm:Single );

fPolar fpolr( float __MagVal, float __ArgVal);
procedure fpolr( var py:fPolar; xMag, xArg:Single );

float cf_imag( fComplex __z );
function cf_imag( zx:fComplex ): Single;

float pf_imag( fPolar __p );
function pf_imag( px:fPolar ): Single;

fComplex cf_inv( fComplex __z );
procedure cf_inv( var zy:fComplex; zx:fComplex );

fPolar pf_inv( fPolar __p );
procedure pf_inv( var py:fPolar; zx:fComplex );

fComplex cf_ipow( fComplex __z, int __exponent );
procedure cf_ipow( var zy:fComplex; zx:fComplex; exponent:Integer );

fPolar pf_ipow( fPolar __p, int __exponent );
procedure pf_ipow( var py:fPolar; px:fPolar; exponent:Integer );

fComplex cf_ln( fComplex __z );
procedure cf_ln( var zy:fComplex; zx:fComplex );

fComplex pf_lntoc( fPolar __p );
procedure pf_lntoc( var zy:fComplex; zx:fPolar );

fComplex cf_log( fComplex __z );
procedure cf_log( var zy:fComplex; zx:fComplex );

fComplex pf_logtoc( fPolar __p );
procedure pf_logtoc( var zy:fComplex; zx:fPolar );

fComplex cf_log2( fComplex __z );
procedure cf_log2( var zy:fComplex; zx:fComplex );

fComplex pf_log2toc( fPolar __p );
procedure pf_log2toc( var zy:fComplex; zx:fPolar );

fComplex cf_log10( fComplex __z );
procedure cf_log10( var zy:fComplex; zx:fComplex );

fComplex pf_log10toc( fPolar __p );
procedure pf_log10toc( var zy:fComplex; zx:fPolar );

fComplex cf_magargtoc( float __mag, float __angle );
procedure cf_magargtoc( var zy:fComplex; mag, angle:Single );

fComplex cf_mul( fComplex __x, fComplex __y );
procedure cf_mul( var zz:fComplex; zx, zy:fComplex );

fPolar pf_mul( fPolar __x, fPolar __y );
procedure pf_mul( var zz:fPolar; zx, zy:fPolar );

fComplex cf_mulRe( fComplex __x, float __yRe );
procedure cf_mulRe( var zz:fComplex; zx:fComplex; yRe:Single );

fPolar pf_mulRe( fPolar __x, float __yRe );
procedure pf_mulRe( var zz:fPolar; zx:fPolar; yRe:Single );

fComplex cf_neg( fComplex __z );
procedure cf_neg( var zy:fComplex; zx:fComplex );

fPolar pf_neg( fPolar __p );
procedure pf_neg( var py:fPolar; px:fPolar );

float cf_norm( fComplex __z );
function cf_norm( zx:fComplex ): Single;

float pf_norm( fPolar __p );
function pf_norm( px:fPolar ): Single;

dComplex pdtocd( dPolar __pd );
procedure pdtocd( var zy:dComplex; px:dPolar );

eComplex pdtoce( dPolar __pd );
procedure pdtoce( var zy:eComplex; px:dPolar );

fComplex pdtocf( dPolar __pd );
procedure pdtocf( var zy:fComplex; px:dPolar );

ePolar pdtope( dPolar __pd );
procedure pdtope( var zy:ePolar; zx:dPolar );

fPolar pdtopf( dPolar __pd );
procedure pdtopf( var zy:fPolar; zx:dPolar );

dComplex petocd( ePolar __pe );
procedure petocd( var zy:dComplex; px:ePolar );

eComplex petoce( ePolar __pe );
procedure petoce( var zy:eComplex; px:ePolar );

fComplex petocf( ePolar __pe );
procedure petocf( var zy:fComplex; px:ePolar );

dPolar petopd( ePolar __pe );
procedure petopd( var zy:dPolar; zx:ePolar );

fPolar petopf( ePolar __pe );
procedure petopf( var zy:fPolar; zx:ePolar );

dComplex pftocd( fPolar __pf );
procedure pftocd( var zy:dComplex; px:fPolar );

eComplex pftoce( fPolar __pf );
procedure pftoce( var zy:eComplex; px:fPolar );

fComplex pftocf( fPolar __pf );
procedure pftocf( var zy:fComplex; px:fPolar );

dPolar pftopd( fPolar __pf );
procedure pftopd( var zy:dPolar; zx:fPolar );

ePolar pftope( fPolar __pf );
procedure pftope( var zy:ePolar; zx:fPolar );

fComplex cf_polar( float mag, float arg ); /* same as cf_magargtoc */
procedure cf_polar( var zy:fComplex; mag, arg:Single );

fComplex cf_pow( fComplex __base, fComplex __exponent );
procedure cf_pow( var zy:fComplex; zx:fComplex; exponent:Integer );

fComplex cf_powReBase( float __base, fComplex __exponent );
procedure cf_powReBase( var zy:fComplex; base:Single; exponent:fComplex );

fComplex cf_powReExpo( fComplex __base, float __exponent );
procedure cf_powReExpo( var zy:fComplex; zx:fComplex; exponent:Single );

fPolar pf_powReExpo( fPolar __base, float __exponent );
procedure pf_powReExpo( var py:fPolar; px:fPolar; exponent:Single );

fComplex cf_quartic( fComplex __z );
procedure cf_quartic( var zy:fComplex; zx:fComplex );

fPolar pf_quartic( fPolar __p );
procedure pf_quartic( var py:fPolar; zx:fPolar );

float cf_real( fComplex __z );
function cf_real( zx:fComplex ): Single;

float pf_real( fPolar __p );
function pf_real( px:fPolar ): Single;

fComplex cf_sin( fComplex __z );
procedure cf_sin( var zy:fComplex; zx:fComplex );

fComplex cf_sinh( fComplex __z );
procedure cf_sinh( var zy:fComplex; zx:fComplex );

fComplex cf_square( fComplex __z );
procedure cf_square( var zy:fComplex; zx:fComplex );

fPolar pf_square( fPolar __p );
procedure pf_square( var py:fPolar; zx:fPolar );

fComplex cf_sqrt( fComplex __z );
procedure cf_sqrt( var zy:fComplex; zx:fComplex );

fPolar pf_sqrt( fPolar __p );
procedure pf_sqrt( var py:fPolar; px:fPolar );

fComplex cf_sub( fComplex __x, fComplex __y );
procedure cf_sub( var zz:fComplex; zx, zy:fComplex );

fComplex cf_subRe( fComplex __x, float __yRe ); /* x - yRe */
procedure cf_subRe( var zz:fComplex; zx:fComplex; yRe:Single );

fComplex cf_subrRe( fComplex __x, float __yRe ); /* yRe - x */
procedure cf_subrRe( var zz:fComplex; zx:fComplex; yRe:Single );

fComplex cf_tan( fComplex __z );
procedure cf_tan( var zy:fComplex; zx:fComplex );

fComplex cf_tanh( fComplex __z );
procedure cf_tanh( var zy:fComplex; zx:fComplex );

Back to Table of Contents

## 4.2 Overloaded C++ Functions

float abs( fComplex _z );
float abs( fPolar _p );

fComplex acos( fComplex _z );

float arg( fComplex _z );
float arg( fPolar _p );

fComplex asin( fComplex _z );

fComplex atan( fComplex _z );

fComplex conj( fComplex _z );
fPolar conj( fPolar _p );

fComplex cos( fComplex _z );

fComplex cosh( fComplex _z );

fComplex cubic( fComplex _z );
fPolar cubic( fPolar _p );

fComplex exp( fComplex _z );
fPolar exptop( fComplex _z );

fComplex fComplex( float Re_part, float Im_part=0 );
fComplex fComplex( dComplex cd );
fComplex fComplex( eComplex ce ); // type-casting constructors
fComplex fComplex( fPolar pf ); // interconversion from polar
fComplex fComplex( dPolar pd );
fComplex fComplex( ePolar pe );

float imag(); // to be used as zim = z.imag();
float imag( fComplex _z ); // to be used as zim = imag( z );

float imag( fPolar _p );
fComplex inv( fComplex _z );
fPolar inv( fPolar _p );

fComplex ipow( fComplex __base, int __expon );
fPolar ipow( fPolar __base, int __expon );

fComplex ln( fComplex _z );
fComplex lntoc( fPolar _p );

fComplex log( fComplex _z );
fComplex logtoc( fPolar _p );

fComplex log2( fComplex _z );
fComplex log2toc( fPolar _p );

fComplex log10( fComplex _z );
fComplex log10toc( fPolar _p );

fComplex magargtoc( float _mag, float _angle );

fComplex neg( fComplex _z );
fPolar neg( fPolar _p );

float norm( fComplex _z );
float norm( fPolar _p );

fComplex pow( fComplex __base, fComplex __expon);
fComplex powReBase( float __base, fComplex __expon );
fComplex pow( float __base, fComplex __expon);
fComplex powReExpo( fComplex __base, float __expon );
fComplex pow( fComplex __base, float __expon );
fPolar powReExpo( fPolar __base, float __expon );

fPolar principal( fPolar _p );
fPolar principal( floag __mag, float __arg );

fComplex quartic( fComplex _z );
fPolar quartic( fPolar _p );

float z.real(); // to be used as zre = z.real();
float real( fComplex _z ); // to be used as zre = real ( _z );
float real( fPolar _p );

fPolar reimtop( float _re, float _im );

fComplex sin( fComplex _z );

fComplex sinh( fComplex _z );

fComplex sqrt( fComplex _z );
fPolar sqrt( fPolar _p );

fComplex square( fComplex _z );
fPolar square( fPolar _z );

fComplex tan( fComplex _z );

fComplex tanh( fComplex _z );

Zurück zum Inhaltsverzeichnis

#

E N D

Copyright for OptiVec and CMATH software and documentation
© 1996-2003 OptiCode - Dr. Martin Sander Software Dev.
All rights reserved!