This is Complex.h in view mode; [Download] [Up]
/* This file is part of 'FractalView' - A Fractal Calculation Program for NeXTStep 3.x Author: Peter Merz Kaerntner Str. 9a 57223 Kreuztal - GERMANY Copyright (C) 1995 Peter Merz THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. License to freely use and distribute this software is hereby granted, by the author, subject to the condition that this copyright notice, remains intact. The author retains the exclusive right to publish, derivative works based on this work, including, but not limited to, revised versions of this work. */ #ifndef _Complex_h #pragma interface #define _Complex_h #include <math.h> class Complex { protected: double re, im; public: Complex(); /* Constructor */ Complex(const Complex& y); /* Constructor */ Complex(double r, double i=0); /* Constructor */ ~Complex(); /* Destructor */ double real() const; /* Selector */ double imag() const; /* Selector */ Complex& operator = (const Complex& y); Complex& operator += (const Complex& y); Complex& operator += (double y); Complex& operator -= (const Complex& y); Complex& operator -= (double y); Complex& operator *= (const Complex& y); Complex& operator *= (double y); Complex& operator /= (const Complex& y); Complex& operator /= (double y); void error(const char* msg) const; protected: friend Complex operator - (const Complex& x); friend Complex operator + (const Complex& x, const Complex& y); friend Complex operator + (const Complex& x, double y); friend Complex operator + (double x, const Complex& y); friend Complex operator - (const Complex& x, const Complex& y); friend Complex operator - (const Complex& x, double y); friend Complex operator - (double x, const Complex& y); friend Complex operator * (const Complex& x, const Complex& y); friend Complex operator * (const Complex& x, double y); friend Complex operator * (double x, const Complex& y); friend Complex operator / (const Complex& x, const Complex& y); friend Complex operator / (const Complex& x, double y); friend Complex operator / (double x, const Complex& y); friend int operator == (const Complex& x, const Complex& y); friend int operator == (const Complex& x, double y); friend int operator != (const Complex& x, const Complex& y); friend int operator != (const Complex& x, double y); friend Complex conj(const Complex& x); friend double real(const Complex& x); friend double imag(const Complex& x); friend double abs(const Complex& x); friend double norm(const Complex& x); friend double arg(const Complex& x); friend Complex polar(double r, double t = 0.0); friend Complex cos(const Complex& x); friend Complex sin(const Complex& x); friend Complex tan(const Complex& x); friend Complex cosh(const Complex& x); friend Complex sinh(const Complex& x); friend Complex exp(const Complex& x); friend Complex log(const Complex& x); friend Complex pow(const Complex& x, int p); friend Complex pow(const Complex& x, const Complex& p); friend Complex pow(const Complex& x, double y); friend Complex sqrt(const Complex& x); }; inline double Complex::real() const { return re; } inline double Complex::imag() const { return im; } inline Complex::Complex() {} inline Complex::Complex(const Complex& y) :re(y.re), im(y.im) {} inline Complex::Complex(double r, double i) :re(r), im(i) {} inline Complex::~Complex() {} inline Complex& Complex::operator = (const Complex& y) { re = y.re; im = y.im; return *this; } inline Complex& Complex::operator += (const Complex& y) { re += y.re; im += y.im; return *this; } inline Complex& Complex::operator += (double y) { re += y; return *this; } inline Complex& Complex::operator -= (const Complex& y) { re -= y.re; im -= y.im; return *this; } inline Complex& Complex::operator -= (double y) { re -= y; return *this; } inline Complex& Complex::operator *= (const Complex& y) { double r = re * y.re - im * y.im; im = re * y.im + im * y.re; re = r; return *this; } inline Complex& Complex::operator *= (double y) { re *= y; im *= y; return *this; } inline int operator == (const Complex& x, const Complex& y) { return x.re == y.re && x.im == y.im; } inline int operator == (const Complex& x, double y) { return x.im == 0.0 && x.re == y; } inline int operator != (const Complex& x, const Complex& y) { return x.re != y.re || x.im != y.im; } inline int operator != (const Complex& x, double y) { return x.im != 0.0 || x.re != y;} inline Complex operator - (const Complex& x) { return Complex(-x.re, -x.im); } inline Complex conj(const Complex& x) { return Complex(x.re, -x.im); } inline Complex operator + (const Complex& x, const Complex& y) { return Complex(x.re + y.re, x.im + y.im); } inline Complex operator + (const Complex& x, double y) { return Complex(x.re + y, x.im); } inline Complex operator + (double x, const Complex& y) { return Complex(x + y.re, y.im); } inline Complex operator - (const Complex& x, const Complex& y) { return Complex(x.re - y.re, x.im - y.im);} inline Complex operator - (const Complex& x, double y) { return Complex(x.re - y, x.im); } inline Complex operator - (double x, const Complex& y) { return Complex(x - y.re, -y.im); } inline Complex operator * (const Complex& x, const Complex& y) { return Complex(x.re * y.re - x.im * y.im, x.re * y.im + x.im * y.re); } inline Complex operator * (const Complex& x, double y) { return Complex(x.re * y, x.im * y); } inline Complex operator * (double x, const Complex& y) { return Complex(x * y.re, x * y.im); } inline double real(const Complex& x) { return x.re; } inline double imag(const Complex& x) { return x.im; } inline double abs(const Complex& x) { return hypot(x.re, x.im); } inline double norm(const Complex& x) { return (x.re*x.re + x.im*x.im); } inline double arg(const Complex& x) { return atan2(x.im, x.re); } inline Complex polar(double r, double t) { return Complex(r * cos(t), r * sin(t)); } #endif
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.