[9102] | 1 | ///
|
---|
| 2 | /// This file is part of ILNumerics Community Edition.
|
---|
| 3 | ///
|
---|
| 4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
| 5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
| 6 | ///
|
---|
| 7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
| 8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
| 9 | /// the Free Software Foundation.
|
---|
| 10 | ///
|
---|
| 11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
| 12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | /// GNU General Public License for more details.
|
---|
| 15 | ///
|
---|
| 16 | /// You should have received a copy of the GNU General Public License
|
---|
| 17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
| 18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | ///
|
---|
| 20 | /// In addition this software uses the following components and/or licenses:
|
---|
| 21 | ///
|
---|
| 22 | /// =================================================================================
|
---|
| 23 | /// The Open Toolkit Library License
|
---|
| 24 | ///
|
---|
| 25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
| 26 | ///
|
---|
| 27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
| 28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
| 29 | /// in the Software without restriction, including without limitation the rights to
|
---|
| 30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
| 31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
| 32 | /// so, subject to the following conditions:
|
---|
| 33 | ///
|
---|
| 34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
| 35 | /// copies or substantial portions of the Software.
|
---|
| 36 | ///
|
---|
| 37 | /// =================================================================================
|
---|
| 38 | ///
|
---|
| 39 |
|
---|
| 40 | #pragma warning disable 162
|
---|
| 41 | using System;
|
---|
| 42 | using System.Collections.Generic;
|
---|
| 43 | using System.Text;
|
---|
| 44 | using System.Runtime.InteropServices;
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | namespace ILNumerics {
|
---|
| 49 | /// <summary>
|
---|
| 50 | /// Floating point complex value data type of double precision
|
---|
| 51 | /// </summary>
|
---|
| 52 | /// <remarks>This class extends the system value types for real numbers to complex double
|
---|
| 53 | /// values. Besides the publicly available members 'real' and 'imag' it provides all the
|
---|
| 54 | /// basis functionality the floating point system.double brings (abs, log, sqrt, tan etc.),
|
---|
| 55 | /// as well as it overrides the basic unary and binary operators for all common system value
|
---|
| 56 | /// types including rarely used types (e.g. UInt16). This includes the basic numerical operations
|
---|
| 57 | /// like '+','-','/','*' and the relational operators: '==','>','>=' etc. Also there are some
|
---|
| 58 | /// explicit and some implicit casting operators from / to complex value into system
|
---|
| 59 | /// value types.</remarks>
|
---|
| 60 | [Serializable]
|
---|
| 61 | [StructLayout(LayoutKind.Sequential)]
|
---|
| 62 | public struct complex : IEquatable<complex> {
|
---|
| 63 | /// <summary>
|
---|
| 64 | /// Real part of this complex number
|
---|
| 65 | /// </summary>
|
---|
| 66 | public double real;
|
---|
| 67 | /// <summary>
|
---|
| 68 | /// Imaginary part of this complex number
|
---|
| 69 | /// </summary>
|
---|
| 70 | public double imag;
|
---|
| 71 | /// <summary>
|
---|
| 72 | /// Imaginary unit
|
---|
| 73 | /// </summary>
|
---|
| 74 | public static readonly complex i = new complex(0.0f,1.0f);
|
---|
| 75 |
|
---|
| 76 | /// <summary>
|
---|
| 77 | /// Constructor creating a new complex value
|
---|
| 78 | /// </summary>
|
---|
| 79 | /// <param name="real">Real part</param>
|
---|
| 80 | /// <param name="imag">Imaginary part</param>
|
---|
| 81 | public complex(double real, double imag) {
|
---|
| 82 | this.real = real;
|
---|
| 83 | this.imag = imag;
|
---|
| 84 | }
|
---|
| 85 | /// <summary>
|
---|
| 86 | /// Complex conjugate
|
---|
| 87 | /// </summary>
|
---|
| 88 | public complex conj {
|
---|
| 89 | get{
|
---|
| 90 | return new complex(real,-imag);
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | /// <summary>
|
---|
| 95 | /// Positive infinity for real and imag part of complex value
|
---|
| 96 | /// </summary>
|
---|
| 97 | public static complex INF {
|
---|
| 98 | get {
|
---|
| 99 | return new complex(
|
---|
| 100 | double.PositiveInfinity,
|
---|
| 101 | double.PositiveInfinity
|
---|
| 102 | );
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /// <summary>
|
---|
| 107 | /// New complex, real and imaginary parts are zero
|
---|
| 108 | /// </summary>
|
---|
| 109 | public static complex Zero {
|
---|
| 110 | get {
|
---|
| 111 | return new complex(0.0,0.0);
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /// <summary>
|
---|
| 116 | /// Complex quantity, marked as being "not a number"
|
---|
| 117 | /// </summary>
|
---|
| 118 | public static complex NaN {
|
---|
| 119 | get {
|
---|
| 120 | return new complex(double.NaN,double.NaN);
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | /// <summary>
|
---|
| 125 | /// Are obj's real and imaginary part identical to the real and imaginary parts of this fcomplex
|
---|
| 126 | /// </summary>
|
---|
| 127 | /// <param name="obj">fcomplex object to determine the equality for</param>
|
---|
| 128 | /// <returns>true if obj is of fcomplex type and its real and imag part has the same
|
---|
| 129 | /// values as the real and imaginary part of this array.</returns>
|
---|
| 130 | public override bool Equals(object obj) {
|
---|
| 131 | if (obj is complex && ((complex)obj) == this)
|
---|
| 132 | return true;
|
---|
| 133 | return false;
|
---|
| 134 | }
|
---|
| 135 | /// <summary>
|
---|
| 136 | /// Check if a complex number equals this complex number
|
---|
| 137 | /// </summary>
|
---|
| 138 | /// <param name="other">other complex number</param>
|
---|
| 139 | /// <returns>true if both, real and imaginary parts of both complex number are (binary) equal, false otherwise</returns>
|
---|
| 140 | public bool Equals(complex other) {
|
---|
| 141 | return real.Equals(other.real) && imag.Equals(other.imag);
|
---|
| 142 | }
|
---|
| 143 | /// <summary>
|
---|
| 144 | /// Hash code of this comples
|
---|
| 145 | /// </summary>
|
---|
| 146 | /// <returns>Hash code of this complex</returns>
|
---|
| 147 | public override int GetHashCode() {
|
---|
| 148 | return 77101 * real.GetHashCode() + imag.GetHashCode();
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | |
---|
| 152 |
|
---|
| 153 | /// <summary>
|
---|
| 154 | /// Add two complex numbers
|
---|
| 155 | /// </summary>
|
---|
| 156 | /// <param name="A">First summand</param>
|
---|
| 157 | /// <param name="B">Second summand</param>
|
---|
| 158 | /// <returns>result</returns>
|
---|
| 159 | public static complex operator +( complex A, complex B) {
|
---|
| 160 | complex ret;
|
---|
| 161 | ret.real = (double) (A.real + B.real );
|
---|
| 162 | ret.imag = (double) (A.imag + B.imag );
|
---|
| 163 | return ret;
|
---|
| 164 | }
|
---|
| 165 | /// <summary>
|
---|
| 166 | /// Subtract two complex values
|
---|
| 167 | /// </summary>
|
---|
| 168 | /// <param name="A">Minuend</param>
|
---|
| 169 | /// <param name="B">Subtrahend</param>
|
---|
| 170 | /// <returns>result</returns>
|
---|
| 171 | public static complex operator -( complex A, complex B) {
|
---|
| 172 | complex ret;
|
---|
| 173 | ret.real = (double) (A.real - B.real );
|
---|
| 174 | ret.imag = (double) (A.imag - B.imag );
|
---|
| 175 | return ret;
|
---|
| 176 | }
|
---|
| 177 | /// <summary>
|
---|
| 178 | /// Multiply two complex values
|
---|
| 179 | /// </summary>
|
---|
| 180 | /// <param name="A">First factor</param>
|
---|
| 181 | /// <param name="B">Second factor</param>
|
---|
| 182 | /// <returns>result</returns>
|
---|
| 183 | public static complex operator *( complex A, complex B) {
|
---|
| 184 | complex ret;
|
---|
| 185 | ret.real = (double) ((A.real * B.real ) - (A.imag * B.imag ));
|
---|
| 186 | ret.imag = (double) ((A.real * B.imag ) + (A.imag * B.real ));
|
---|
| 187 | return ret;
|
---|
| 188 | }
|
---|
| 189 | /// <summary>
|
---|
| 190 | /// Divide two numbers
|
---|
| 191 | /// </summary>
|
---|
| 192 | /// <param name="A">Divident</param>
|
---|
| 193 | /// <param name="B">Divisor</param>
|
---|
| 194 | /// <returns>Result</returns>
|
---|
| 195 | /// <remarks><para>Unless the operator must handle special inputs (Inf or 0 values),
|
---|
| 196 | /// the algorithm described in [1] is used for division. This is considered to be
|
---|
| 197 | /// more robust against floating point overflow than the naive approach of simple
|
---|
| 198 | /// cartesian division.</para>
|
---|
| 199 | /// <para>References: [1]: Smith, R.L., Algorithm 116: Complex division. Commun.ACM 5,8 (1962),435 <br />
|
---|
| 200 | /// [2]: Stewart, G.W., A note on complex division, ACM trans.on math software, Vol.11, N.3 (1985)</para></remarks>
|
---|
| 201 | public static complex operator /( complex A, complex B) {
|
---|
| 202 | if (B.imag == 0) return A / B.real;
|
---|
| 203 | return A * (1 / B);
|
---|
| 204 | if (IsNaN(A) || complex .IsNaN(B)) return NaN;
|
---|
| 205 | //if ( complex .IsInfinity(B)) return NaN;
|
---|
| 206 | //if (A.real == 0 && A.imag == 0) return ( complex )0;
|
---|
| 207 | complex ret;
|
---|
| 208 | if (B.real == 0) {
|
---|
| 209 | ret.imag = (double) -(A.real / B.imag);
|
---|
| 210 | ret.real = (double) (A.imag / B.imag);
|
---|
| 211 | return ret;
|
---|
| 212 | }
|
---|
| 213 | // this would be the naive approach. But it come with to little robustness against overflow
|
---|
| 214 | //double norm2 = B.real * B.real + B.imag * B.imag;
|
---|
| 215 | //if (norm2 == 0) return INF; // this may be removed, since division by 0 results in inf anyway ?
|
---|
| 216 | //ret.real = (double) (((A.real * B.real ) + (A.imag * B.imag )) / norm2);
|
---|
| 217 | //ret.imag = (double) (((A.imag * B.real ) - (A.real * B.imag )) / norm2);
|
---|
| 218 |
|
---|
| 219 | // this algorithm is taken from [1]. The one described in [2] was not taken. Tests
|
---|
| 220 | // did not show any advantage when using double precision floating point arithmetic.
|
---|
| 221 | double tmp1, tmp2;
|
---|
| 222 | if (Math.Abs(B.real) >= Math.Abs(B.imag)) {
|
---|
| 223 | tmp1 = (double) (B.imag * (1/B.real));
|
---|
| 224 | tmp2 = (double) (B.real + B.imag*tmp1);
|
---|
| 225 | ret.real = (double) (A.real + A.imag*tmp1)/tmp2;
|
---|
| 226 | ret.imag = (double) (A.imag - A.real*tmp1)/tmp2;
|
---|
| 227 | } else {
|
---|
| 228 | tmp1 = (double) (B.real * (1/B.imag));
|
---|
| 229 | tmp2 = (double) (B.imag + B.real*tmp1);
|
---|
| 230 | ret.real = (double) (A.imag + A.real*tmp1)/tmp2;
|
---|
| 231 | ret.imag = - (double) (A.real - A.imag*tmp1)/tmp2;
|
---|
| 232 | }
|
---|
| 233 | return ret;
|
---|
| 234 | }
|
---|
| 235 | /// <summary>
|
---|
| 236 | /// Equality comparison for complex numbers
|
---|
| 237 | /// </summary>
|
---|
| 238 | /// <param name="A">Left side</param>
|
---|
| 239 | /// <param name="B">Right side</param>
|
---|
| 240 | /// <returns>true, if real and imaginary part are identical</returns>
|
---|
| 241 | public static bool operator ==( complex A, complex B) {
|
---|
| 242 | return (A.imag == B.imag ) && (A.real == B.real );
|
---|
| 243 | }
|
---|
| 244 | /// <summary>
|
---|
| 245 | /// Unequality comparison for complex numbers
|
---|
| 246 | /// </summary>
|
---|
| 247 | /// <param name="A">Left side</param>
|
---|
| 248 | /// <param name="B">Right side</param>
|
---|
| 249 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 250 | public static bool operator !=( complex A, complex B) {
|
---|
| 251 | return (A.imag != B.imag ) || (A.real != B.real );
|
---|
| 252 | }
|
---|
| 253 | /// <summary>
|
---|
| 254 | /// Greater than comparison for complex numbers
|
---|
| 255 | /// </summary>
|
---|
| 256 | /// <param name="A">Left side</param>
|
---|
| 257 | /// <param name="B">Right side</param>
|
---|
| 258 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 259 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 260 | public static bool operator > ( complex A, complex B) {
|
---|
| 261 | return (A.real > B.real );
|
---|
| 262 | }
|
---|
| 263 | /// <summary>
|
---|
| 264 | /// Lower than comparison for complex numbers
|
---|
| 265 | /// </summary>
|
---|
| 266 | /// <param name="A">Left side</param>
|
---|
| 267 | /// <param name="B">Right side</param>
|
---|
| 268 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 269 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 270 | public static bool operator < ( complex A, complex B) {
|
---|
| 271 | return (A.real < B.real );
|
---|
| 272 | }
|
---|
| 273 | /// <summary>
|
---|
| 274 | /// Greater than or equal to comparison for complex numbers
|
---|
| 275 | /// </summary>
|
---|
| 276 | /// <param name="A">Left side</param>
|
---|
| 277 | /// <param name="B">Right side</param>
|
---|
| 278 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 279 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 280 | public static bool operator >=( complex A, complex B) {
|
---|
| 281 | return (A.real >= B.real );
|
---|
| 282 | }
|
---|
| 283 | /// <summary>
|
---|
| 284 | /// Lower than or equal to comparison for complex numbers
|
---|
| 285 | /// </summary>
|
---|
| 286 | /// <param name="A">Left side</param>
|
---|
| 287 | /// <param name="B">Right side</param>
|
---|
| 288 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 289 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 290 | public static bool operator <=( complex A, complex B) {
|
---|
| 291 | return (A.real <= B.real );
|
---|
| 292 | }
|
---|
| 293 | |
---|
| 294 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 295 | |
---|
| 296 |
|
---|
| 297 | /// <summary>
|
---|
| 298 | /// Add two complex numbers
|
---|
| 299 | /// </summary>
|
---|
| 300 | /// <param name="A">First summand</param>
|
---|
| 301 | /// <param name="B">Second summand</param>
|
---|
| 302 | /// <returns>result</returns>
|
---|
| 303 | public static complex operator +( complex A, fcomplex B) {
|
---|
| 304 | complex ret;
|
---|
| 305 | ret.real = (double) (A.real + B.real );
|
---|
| 306 | ret.imag = (double) (A.imag + B.imag );
|
---|
| 307 | return ret;
|
---|
| 308 | }
|
---|
| 309 | /// <summary>
|
---|
| 310 | /// Subtract two complex values
|
---|
| 311 | /// </summary>
|
---|
| 312 | /// <param name="A">Minuend</param>
|
---|
| 313 | /// <param name="B">Subtrahend</param>
|
---|
| 314 | /// <returns>result</returns>
|
---|
| 315 | public static complex operator -( complex A, fcomplex B) {
|
---|
| 316 | complex ret;
|
---|
| 317 | ret.real = (double) (A.real - B.real );
|
---|
| 318 | ret.imag = (double) (A.imag - B.imag );
|
---|
| 319 | return ret;
|
---|
| 320 | }
|
---|
| 321 | /// <summary>
|
---|
| 322 | /// Multiply two complex values
|
---|
| 323 | /// </summary>
|
---|
| 324 | /// <param name="A">First factor</param>
|
---|
| 325 | /// <param name="B">Second factor</param>
|
---|
| 326 | /// <returns>result</returns>
|
---|
| 327 | public static complex operator *( complex A, fcomplex B) {
|
---|
| 328 | complex ret;
|
---|
| 329 | ret.real = (double) ((A.real * B.real ) - (A.imag * B.imag ));
|
---|
| 330 | ret.imag = (double) ((A.real * B.imag ) + (A.imag * B.real ));
|
---|
| 331 | return ret;
|
---|
| 332 | }
|
---|
| 333 | /// <summary>
|
---|
| 334 | /// Divide two numbers
|
---|
| 335 | /// </summary>
|
---|
| 336 | /// <param name="A">Divident</param>
|
---|
| 337 | /// <param name="B">Divisor</param>
|
---|
| 338 | /// <returns>Result</returns>
|
---|
| 339 | /// <remarks><para>Unless the operator must handle special inputs (Inf or 0 values),
|
---|
| 340 | /// the algorithm described in [1] is used for division. This is considered to be
|
---|
| 341 | /// more robust against floating point overflow than the naive approach of simple
|
---|
| 342 | /// cartesian division.</para>
|
---|
| 343 | /// <para>References: [1]: Smith, R.L., Algorithm 116: Complex division. Commun.ACM 5,8 (1962),435 <br />
|
---|
| 344 | /// [2]: Stewart, G.W., A note on complex division, ACM trans.on math software, Vol.11, N.3 (1985)</para></remarks>
|
---|
| 345 | public static complex operator /( complex A, fcomplex B) {
|
---|
| 346 | if (B.imag == 0) return A / B.real;
|
---|
| 347 | return A * (1 / B);
|
---|
| 348 | if (IsNaN(A) || fcomplex .IsNaN(B)) return NaN;
|
---|
| 349 | //if ( fcomplex .IsInfinity(B)) return NaN;
|
---|
| 350 | //if (A.real == 0 && A.imag == 0) return ( complex )0;
|
---|
| 351 | complex ret;
|
---|
| 352 | if (B.real == 0) {
|
---|
| 353 | ret.imag = (double) -(A.real / B.imag);
|
---|
| 354 | ret.real = (double) (A.imag / B.imag);
|
---|
| 355 | return ret;
|
---|
| 356 | }
|
---|
| 357 | // this would be the naive approach. But it come with to little robustness against overflow
|
---|
| 358 | //double norm2 = B.real * B.real + B.imag * B.imag;
|
---|
| 359 | //if (norm2 == 0) return INF; // this may be removed, since division by 0 results in inf anyway ?
|
---|
| 360 | //ret.real = (double) (((A.real * B.real ) + (A.imag * B.imag )) / norm2);
|
---|
| 361 | //ret.imag = (double) (((A.imag * B.real ) - (A.real * B.imag )) / norm2);
|
---|
| 362 |
|
---|
| 363 | // this algorithm is taken from [1]. The one described in [2] was not taken. Tests
|
---|
| 364 | // did not show any advantage when using double precision floating point arithmetic.
|
---|
| 365 | double tmp1, tmp2;
|
---|
| 366 | if (Math.Abs(B.real) >= Math.Abs(B.imag)) {
|
---|
| 367 | tmp1 = (double) (B.imag * (1/B.real));
|
---|
| 368 | tmp2 = (double) (B.real + B.imag*tmp1);
|
---|
| 369 | ret.real = (double) (A.real + A.imag*tmp1)/tmp2;
|
---|
| 370 | ret.imag = (double) (A.imag - A.real*tmp1)/tmp2;
|
---|
| 371 | } else {
|
---|
| 372 | tmp1 = (double) (B.real * (1/B.imag));
|
---|
| 373 | tmp2 = (double) (B.imag + B.real*tmp1);
|
---|
| 374 | ret.real = (double) (A.imag + A.real*tmp1)/tmp2;
|
---|
| 375 | ret.imag = - (double) (A.real - A.imag*tmp1)/tmp2;
|
---|
| 376 | }
|
---|
| 377 | return ret;
|
---|
| 378 | }
|
---|
| 379 | /// <summary>
|
---|
| 380 | /// Equality comparison for complex numbers
|
---|
| 381 | /// </summary>
|
---|
| 382 | /// <param name="A">Left side</param>
|
---|
| 383 | /// <param name="B">Right side</param>
|
---|
| 384 | /// <returns>true, if real and imaginary part are identical</returns>
|
---|
| 385 | public static bool operator ==( complex A, fcomplex B) {
|
---|
| 386 | return (A.imag == B.imag ) && (A.real == B.real );
|
---|
| 387 | }
|
---|
| 388 | /// <summary>
|
---|
| 389 | /// Unequality comparison for complex numbers
|
---|
| 390 | /// </summary>
|
---|
| 391 | /// <param name="A">Left side</param>
|
---|
| 392 | /// <param name="B">Right side</param>
|
---|
| 393 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 394 | public static bool operator !=( complex A, fcomplex B) {
|
---|
| 395 | return (A.imag != B.imag ) || (A.real != B.real );
|
---|
| 396 | }
|
---|
| 397 | /// <summary>
|
---|
| 398 | /// Greater than comparison for complex numbers
|
---|
| 399 | /// </summary>
|
---|
| 400 | /// <param name="A">Left side</param>
|
---|
| 401 | /// <param name="B">Right side</param>
|
---|
| 402 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 403 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 404 | public static bool operator > ( complex A, fcomplex B) {
|
---|
| 405 | return (A.real > B.real );
|
---|
| 406 | }
|
---|
| 407 | /// <summary>
|
---|
| 408 | /// Lower than comparison for complex numbers
|
---|
| 409 | /// </summary>
|
---|
| 410 | /// <param name="A">Left side</param>
|
---|
| 411 | /// <param name="B">Right side</param>
|
---|
| 412 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 413 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 414 | public static bool operator < ( complex A, fcomplex B) {
|
---|
| 415 | return (A.real < B.real );
|
---|
| 416 | }
|
---|
| 417 | /// <summary>
|
---|
| 418 | /// Greater than or equal to comparison for complex numbers
|
---|
| 419 | /// </summary>
|
---|
| 420 | /// <param name="A">Left side</param>
|
---|
| 421 | /// <param name="B">Right side</param>
|
---|
| 422 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 423 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 424 | public static bool operator >=( complex A, fcomplex B) {
|
---|
| 425 | return (A.real >= B.real );
|
---|
| 426 | }
|
---|
| 427 | /// <summary>
|
---|
| 428 | /// Lower than or equal to comparison for complex numbers
|
---|
| 429 | /// </summary>
|
---|
| 430 | /// <param name="A">Left side</param>
|
---|
| 431 | /// <param name="B">Right side</param>
|
---|
| 432 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 433 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 434 | public static bool operator <=( complex A, fcomplex B) {
|
---|
| 435 | return (A.real <= B.real );
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 439 |
|
---|
| 440 | |
---|
| 441 |
|
---|
| 442 | /// <summary>
|
---|
| 443 | /// Add two complex numbers
|
---|
| 444 | /// </summary>
|
---|
| 445 | /// <param name="A">First summand</param>
|
---|
| 446 | /// <param name="B">Second summand</param>
|
---|
| 447 | /// <returns>Result</returns>
|
---|
| 448 | public static complex operator +( complex A, double B) {
|
---|
| 449 | complex ret;
|
---|
| 450 | ret.real = (double) (A.real + B);
|
---|
| 451 | ret.imag = (double) A.imag;
|
---|
| 452 | return ret;
|
---|
| 453 | }
|
---|
| 454 | /// <summary>
|
---|
| 455 | /// Subtract two values
|
---|
| 456 | /// </summary>
|
---|
| 457 | /// <param name="A">Minuend</param>
|
---|
| 458 | /// <param name="B">Subtrahend</param>
|
---|
| 459 | /// <returns>result</returns>
|
---|
| 460 | public static complex operator -( complex A, double B) {
|
---|
| 461 | complex ret;
|
---|
| 462 | ret.real = (double) (A.real - B);
|
---|
| 463 | ret.imag = (double) A.imag;
|
---|
| 464 | return ret;
|
---|
| 465 | }
|
---|
| 466 | /// <summary>
|
---|
| 467 | /// Multiply two values
|
---|
| 468 | /// </summary>
|
---|
| 469 | /// <param name="A">First factor</param>
|
---|
| 470 | /// <param name="B">Second factor</param>
|
---|
| 471 | /// <returns>result</returns>
|
---|
| 472 | public static complex operator *( complex A, double B) {
|
---|
| 473 | complex ret;
|
---|
| 474 | ret.real = (double) (A.real * B);
|
---|
| 475 | ret.imag = (double) (A.imag * B);
|
---|
| 476 | return ret;
|
---|
| 477 | }
|
---|
| 478 | /// <summary>
|
---|
| 479 | /// Divide two numbers
|
---|
| 480 | /// </summary>
|
---|
| 481 | /// <param name="A">Divident</param>
|
---|
| 482 | /// <param name="B">Divisor</param>
|
---|
| 483 | /// <returns>result</returns>
|
---|
| 484 | public static complex operator /( complex A, double B) {
|
---|
| 485 | if (IsNaN(A)) return NaN;
|
---|
| 486 |
|
---|
| 487 | if (double.IsNaN(B)) return NaN;
|
---|
| 488 | if (A.real == 0 && A.imag == 0) {
|
---|
| 489 | if (B == 0) return NaN;
|
---|
| 490 | return ( complex )0;
|
---|
| 491 | } else {
|
---|
| 492 |
|
---|
| 493 | if (double .IsInfinity(B))
|
---|
| 494 | {
|
---|
| 495 | if (IsInfinity(A)) {
|
---|
| 496 | return NaN;
|
---|
| 497 | } else {
|
---|
| 498 | return ( complex )0;
|
---|
| 499 | }
|
---|
| 500 | }
|
---|
| 501 | }
|
---|
| 502 | complex ret;
|
---|
| 503 | if (B == 0) return INF ;
|
---|
| 504 | ret.real = (double) (A.real / B);
|
---|
| 505 | ret.imag = (double) (A.imag / B);
|
---|
| 506 | return ret;
|
---|
| 507 | }
|
---|
| 508 | /// <summary>
|
---|
| 509 | /// Equality comparison for complex numbers
|
---|
| 510 | /// </summary>
|
---|
| 511 | /// <param name="A">Left side</param>
|
---|
| 512 | /// <param name="B">Right side</param>
|
---|
| 513 | /// <returns>result</returns>
|
---|
| 514 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 515 | public static bool operator ==( complex A, double B) {
|
---|
| 516 | return (A.real == B && A.imag == 0.0);
|
---|
| 517 | }
|
---|
| 518 | /// <summary>
|
---|
| 519 | /// Unequality comparison for complex numbers
|
---|
| 520 | /// </summary>
|
---|
| 521 | /// <param name="A">Left side</param>
|
---|
| 522 | /// <param name="B">Right side</param>
|
---|
| 523 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 524 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 525 | public static bool operator !=( complex A, double B) {
|
---|
| 526 | return (A.imag != 0.0) || (A.real != B);
|
---|
| 527 | }
|
---|
| 528 | /// <summary>
|
---|
| 529 | /// Freater than comparison for complex numbers
|
---|
| 530 | /// </summary>
|
---|
| 531 | /// <param name="A">Left side</param>
|
---|
| 532 | /// <param name="B">Right side</param>
|
---|
| 533 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 534 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 535 | public static bool operator > ( complex A, double B) {
|
---|
| 536 | return (A.real > B);
|
---|
| 537 | }
|
---|
| 538 | /// <summary>
|
---|
| 539 | /// Lower than comparison for complex numbers
|
---|
| 540 | /// </summary>
|
---|
| 541 | /// <param name="A">Left side</param>
|
---|
| 542 | /// <param name="B">Right side</param>
|
---|
| 543 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 544 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 545 | public static bool operator <( complex A, double B) {
|
---|
| 546 | return (A.real < B);
|
---|
| 547 | }
|
---|
| 548 | /// <summary>
|
---|
| 549 | /// Greater than or equal to comparison for complex numbers
|
---|
| 550 | /// </summary>
|
---|
| 551 | /// <param name="A">Left side</param>
|
---|
| 552 | /// <param name="B">Right side</param>
|
---|
| 553 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 554 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 555 | public static bool operator >=( complex A, double B) {
|
---|
| 556 | return (A.real >= B);
|
---|
| 557 | }
|
---|
| 558 | /// <summary>
|
---|
| 559 | /// Lower than or equal to comparison for complex numbers
|
---|
| 560 | /// </summary>
|
---|
| 561 | /// <param name="A">Left side</param>
|
---|
| 562 | /// <param name="B">Right side</param>
|
---|
| 563 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 564 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 565 | public static bool operator <=( complex A, double B) {
|
---|
| 566 | return (A.real <= B);
|
---|
| 567 | }
|
---|
| 568 | |
---|
| 569 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 570 | |
---|
| 571 |
|
---|
| 572 | /// <summary>
|
---|
| 573 | /// Add two complex numbers
|
---|
| 574 | /// </summary>
|
---|
| 575 | /// <param name="A">First summand</param>
|
---|
| 576 | /// <param name="B">Second summand</param>
|
---|
| 577 | /// <returns>Result</returns>
|
---|
| 578 | public static complex operator +( complex A, Int64 B) {
|
---|
| 579 | complex ret;
|
---|
| 580 | ret.real = (double) (A.real + B);
|
---|
| 581 | ret.imag = (double) A.imag;
|
---|
| 582 | return ret;
|
---|
| 583 | }
|
---|
| 584 | /// <summary>
|
---|
| 585 | /// Subtract two values
|
---|
| 586 | /// </summary>
|
---|
| 587 | /// <param name="A">Minuend</param>
|
---|
| 588 | /// <param name="B">Subtrahend</param>
|
---|
| 589 | /// <returns>result</returns>
|
---|
| 590 | public static complex operator -( complex A, Int64 B) {
|
---|
| 591 | complex ret;
|
---|
| 592 | ret.real = (double) (A.real - B);
|
---|
| 593 | ret.imag = (double) A.imag;
|
---|
| 594 | return ret;
|
---|
| 595 | }
|
---|
| 596 | /// <summary>
|
---|
| 597 | /// Multiply two values
|
---|
| 598 | /// </summary>
|
---|
| 599 | /// <param name="A">First factor</param>
|
---|
| 600 | /// <param name="B">Second factor</param>
|
---|
| 601 | /// <returns>result</returns>
|
---|
| 602 | public static complex operator *( complex A, Int64 B) {
|
---|
| 603 | complex ret;
|
---|
| 604 | ret.real = (double) (A.real * B);
|
---|
| 605 | ret.imag = (double) (A.imag * B);
|
---|
| 606 | return ret;
|
---|
| 607 | }
|
---|
| 608 | /// <summary>
|
---|
| 609 | /// Divide two numbers
|
---|
| 610 | /// </summary>
|
---|
| 611 | /// <param name="A">Divident</param>
|
---|
| 612 | /// <param name="B">Divisor</param>
|
---|
| 613 | /// <returns>result</returns>
|
---|
| 614 | public static complex operator /( complex A, Int64 B) {
|
---|
| 615 | if (IsNaN(A)) return NaN;
|
---|
| 616 |
|
---|
| 617 | if (A.real == 0 && A.imag == 0) {
|
---|
| 618 | if (B == 0) return NaN;
|
---|
| 619 | return ( complex )0;
|
---|
| 620 | } else {
|
---|
| 621 | if (false)
|
---|
| 622 | {
|
---|
| 623 | if (IsInfinity(A)) {
|
---|
| 624 | return NaN;
|
---|
| 625 | } else {
|
---|
| 626 | return ( complex )0;
|
---|
| 627 | }
|
---|
| 628 | }
|
---|
| 629 | }
|
---|
| 630 | complex ret;
|
---|
| 631 | if (B == 0) return INF ;
|
---|
| 632 | ret.real = (double) (A.real / B);
|
---|
| 633 | ret.imag = (double) (A.imag / B);
|
---|
| 634 | return ret;
|
---|
| 635 | }
|
---|
| 636 | /// <summary>
|
---|
| 637 | /// Equality comparison for complex numbers
|
---|
| 638 | /// </summary>
|
---|
| 639 | /// <param name="A">Left side</param>
|
---|
| 640 | /// <param name="B">Right side</param>
|
---|
| 641 | /// <returns>result</returns>
|
---|
| 642 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 643 | public static bool operator ==( complex A, Int64 B) {
|
---|
| 644 | return (A.real == B && A.imag == 0.0);
|
---|
| 645 | }
|
---|
| 646 | /// <summary>
|
---|
| 647 | /// Unequality comparison for complex numbers
|
---|
| 648 | /// </summary>
|
---|
| 649 | /// <param name="A">Left side</param>
|
---|
| 650 | /// <param name="B">Right side</param>
|
---|
| 651 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 652 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 653 | public static bool operator !=( complex A, Int64 B) {
|
---|
| 654 | return (A.imag != 0.0) || (A.real != B);
|
---|
| 655 | }
|
---|
| 656 | /// <summary>
|
---|
| 657 | /// Freater than comparison for complex numbers
|
---|
| 658 | /// </summary>
|
---|
| 659 | /// <param name="A">Left side</param>
|
---|
| 660 | /// <param name="B">Right side</param>
|
---|
| 661 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 662 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 663 | public static bool operator > ( complex A, Int64 B) {
|
---|
| 664 | return (A.real > B);
|
---|
| 665 | }
|
---|
| 666 | /// <summary>
|
---|
| 667 | /// Lower than comparison for complex numbers
|
---|
| 668 | /// </summary>
|
---|
| 669 | /// <param name="A">Left side</param>
|
---|
| 670 | /// <param name="B">Right side</param>
|
---|
| 671 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 672 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 673 | public static bool operator <( complex A, Int64 B) {
|
---|
| 674 | return (A.real < B);
|
---|
| 675 | }
|
---|
| 676 | /// <summary>
|
---|
| 677 | /// Greater than or equal to comparison for complex numbers
|
---|
| 678 | /// </summary>
|
---|
| 679 | /// <param name="A">Left side</param>
|
---|
| 680 | /// <param name="B">Right side</param>
|
---|
| 681 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 682 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 683 | public static bool operator >=( complex A, Int64 B) {
|
---|
| 684 | return (A.real >= B);
|
---|
| 685 | }
|
---|
| 686 | /// <summary>
|
---|
| 687 | /// Lower than or equal to comparison for complex numbers
|
---|
| 688 | /// </summary>
|
---|
| 689 | /// <param name="A">Left side</param>
|
---|
| 690 | /// <param name="B">Right side</param>
|
---|
| 691 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 692 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 693 | public static bool operator <=( complex A, Int64 B) {
|
---|
| 694 | return (A.real <= B);
|
---|
| 695 | }
|
---|
| 696 |
|
---|
| 697 | /// <summary>
|
---|
| 698 | /// Add two complex numbers
|
---|
| 699 | /// </summary>
|
---|
| 700 | /// <param name="A">First summand</param>
|
---|
| 701 | /// <param name="B">Second summand</param>
|
---|
| 702 | /// <returns>Result</returns>
|
---|
| 703 | public static complex operator +( complex A, Int32 B) {
|
---|
| 704 | complex ret;
|
---|
| 705 | ret.real = (double) (A.real + B);
|
---|
| 706 | ret.imag = (double) A.imag;
|
---|
| 707 | return ret;
|
---|
| 708 | }
|
---|
| 709 | /// <summary>
|
---|
| 710 | /// Subtract two values
|
---|
| 711 | /// </summary>
|
---|
| 712 | /// <param name="A">Minuend</param>
|
---|
| 713 | /// <param name="B">Subtrahend</param>
|
---|
| 714 | /// <returns>result</returns>
|
---|
| 715 | public static complex operator -( complex A, Int32 B) {
|
---|
| 716 | complex ret;
|
---|
| 717 | ret.real = (double) (A.real - B);
|
---|
| 718 | ret.imag = (double) A.imag;
|
---|
| 719 | return ret;
|
---|
| 720 | }
|
---|
| 721 | /// <summary>
|
---|
| 722 | /// Multiply two values
|
---|
| 723 | /// </summary>
|
---|
| 724 | /// <param name="A">First factor</param>
|
---|
| 725 | /// <param name="B">Second factor</param>
|
---|
| 726 | /// <returns>result</returns>
|
---|
| 727 | public static complex operator *( complex A, Int32 B) {
|
---|
| 728 | complex ret;
|
---|
| 729 | ret.real = (double) (A.real * B);
|
---|
| 730 | ret.imag = (double) (A.imag * B);
|
---|
| 731 | return ret;
|
---|
| 732 | }
|
---|
| 733 | /// <summary>
|
---|
| 734 | /// Divide two numbers
|
---|
| 735 | /// </summary>
|
---|
| 736 | /// <param name="A">Divident</param>
|
---|
| 737 | /// <param name="B">Divisor</param>
|
---|
| 738 | /// <returns>result</returns>
|
---|
| 739 | public static complex operator /( complex A, Int32 B) {
|
---|
| 740 | if (IsNaN(A)) return NaN;
|
---|
| 741 |
|
---|
| 742 | if (A.real == 0 && A.imag == 0) {
|
---|
| 743 | if (B == 0) return NaN;
|
---|
| 744 | return ( complex )0;
|
---|
| 745 | } else {
|
---|
| 746 | if (false)
|
---|
| 747 | {
|
---|
| 748 | if (IsInfinity(A)) {
|
---|
| 749 | return NaN;
|
---|
| 750 | } else {
|
---|
| 751 | return ( complex )0;
|
---|
| 752 | }
|
---|
| 753 | }
|
---|
| 754 | }
|
---|
| 755 | complex ret;
|
---|
| 756 | if (B == 0) return INF ;
|
---|
| 757 | ret.real = (double) (A.real / B);
|
---|
| 758 | ret.imag = (double) (A.imag / B);
|
---|
| 759 | return ret;
|
---|
| 760 | }
|
---|
| 761 | /// <summary>
|
---|
| 762 | /// Equality comparison for complex numbers
|
---|
| 763 | /// </summary>
|
---|
| 764 | /// <param name="A">Left side</param>
|
---|
| 765 | /// <param name="B">Right side</param>
|
---|
| 766 | /// <returns>result</returns>
|
---|
| 767 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 768 | public static bool operator ==( complex A, Int32 B) {
|
---|
| 769 | return (A.real == B && A.imag == 0.0);
|
---|
| 770 | }
|
---|
| 771 | /// <summary>
|
---|
| 772 | /// Unequality comparison for complex numbers
|
---|
| 773 | /// </summary>
|
---|
| 774 | /// <param name="A">Left side</param>
|
---|
| 775 | /// <param name="B">Right side</param>
|
---|
| 776 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 777 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 778 | public static bool operator !=( complex A, Int32 B) {
|
---|
| 779 | return (A.imag != 0.0) || (A.real != B);
|
---|
| 780 | }
|
---|
| 781 | /// <summary>
|
---|
| 782 | /// Freater than comparison for complex numbers
|
---|
| 783 | /// </summary>
|
---|
| 784 | /// <param name="A">Left side</param>
|
---|
| 785 | /// <param name="B">Right side</param>
|
---|
| 786 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 787 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 788 | public static bool operator > ( complex A, Int32 B) {
|
---|
| 789 | return (A.real > B);
|
---|
| 790 | }
|
---|
| 791 | /// <summary>
|
---|
| 792 | /// Lower than comparison for complex numbers
|
---|
| 793 | /// </summary>
|
---|
| 794 | /// <param name="A">Left side</param>
|
---|
| 795 | /// <param name="B">Right side</param>
|
---|
| 796 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 797 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 798 | public static bool operator <( complex A, Int32 B) {
|
---|
| 799 | return (A.real < B);
|
---|
| 800 | }
|
---|
| 801 | /// <summary>
|
---|
| 802 | /// Greater than or equal to comparison for complex numbers
|
---|
| 803 | /// </summary>
|
---|
| 804 | /// <param name="A">Left side</param>
|
---|
| 805 | /// <param name="B">Right side</param>
|
---|
| 806 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 807 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 808 | public static bool operator >=( complex A, Int32 B) {
|
---|
| 809 | return (A.real >= B);
|
---|
| 810 | }
|
---|
| 811 | /// <summary>
|
---|
| 812 | /// Lower than or equal to comparison for complex numbers
|
---|
| 813 | /// </summary>
|
---|
| 814 | /// <param name="A">Left side</param>
|
---|
| 815 | /// <param name="B">Right side</param>
|
---|
| 816 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 817 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 818 | public static bool operator <=( complex A, Int32 B) {
|
---|
| 819 | return (A.real <= B);
|
---|
| 820 | }
|
---|
| 821 |
|
---|
| 822 | /// <summary>
|
---|
| 823 | /// Add two complex numbers
|
---|
| 824 | /// </summary>
|
---|
| 825 | /// <param name="A">First summand</param>
|
---|
| 826 | /// <param name="B">Second summand</param>
|
---|
| 827 | /// <returns>Result</returns>
|
---|
| 828 | public static complex operator +( complex A, float B) {
|
---|
| 829 | complex ret;
|
---|
| 830 | ret.real = (double) (A.real + B);
|
---|
| 831 | ret.imag = (double) A.imag;
|
---|
| 832 | return ret;
|
---|
| 833 | }
|
---|
| 834 | /// <summary>
|
---|
| 835 | /// Subtract two values
|
---|
| 836 | /// </summary>
|
---|
| 837 | /// <param name="A">Minuend</param>
|
---|
| 838 | /// <param name="B">Subtrahend</param>
|
---|
| 839 | /// <returns>result</returns>
|
---|
| 840 | public static complex operator -( complex A, float B) {
|
---|
| 841 | complex ret;
|
---|
| 842 | ret.real = (double) (A.real - B);
|
---|
| 843 | ret.imag = (double) A.imag;
|
---|
| 844 | return ret;
|
---|
| 845 | }
|
---|
| 846 | /// <summary>
|
---|
| 847 | /// Multiply two values
|
---|
| 848 | /// </summary>
|
---|
| 849 | /// <param name="A">First factor</param>
|
---|
| 850 | /// <param name="B">Second factor</param>
|
---|
| 851 | /// <returns>result</returns>
|
---|
| 852 | public static complex operator *( complex A, float B) {
|
---|
| 853 | complex ret;
|
---|
| 854 | ret.real = (double) (A.real * B);
|
---|
| 855 | ret.imag = (double) (A.imag * B);
|
---|
| 856 | return ret;
|
---|
| 857 | }
|
---|
| 858 | /// <summary>
|
---|
| 859 | /// Divide two numbers
|
---|
| 860 | /// </summary>
|
---|
| 861 | /// <param name="A">Divident</param>
|
---|
| 862 | /// <param name="B">Divisor</param>
|
---|
| 863 | /// <returns>result</returns>
|
---|
| 864 | public static complex operator /( complex A, float B) {
|
---|
| 865 | if (IsNaN(A)) return NaN;
|
---|
| 866 | if (float.IsNaN(B)) return NaN;
|
---|
| 867 | if (A.real == 0 && A.imag == 0) {
|
---|
| 868 | if (B == 0) return NaN;
|
---|
| 869 | return ( complex )0;
|
---|
| 870 | } else {
|
---|
| 871 | if (float.IsInfinity(B))
|
---|
| 872 | {
|
---|
| 873 | if (IsInfinity(A)) {
|
---|
| 874 | return NaN;
|
---|
| 875 | } else {
|
---|
| 876 | return ( complex )0;
|
---|
| 877 | }
|
---|
| 878 | }
|
---|
| 879 | }
|
---|
| 880 | complex ret;
|
---|
| 881 | if (B == 0) return INF ;
|
---|
| 882 | ret.real = (double) (A.real / B);
|
---|
| 883 | ret.imag = (double) (A.imag / B);
|
---|
| 884 | return ret;
|
---|
| 885 | }
|
---|
| 886 | /// <summary>
|
---|
| 887 | /// Equality comparison for complex numbers
|
---|
| 888 | /// </summary>
|
---|
| 889 | /// <param name="A">Left side</param>
|
---|
| 890 | /// <param name="B">Right side</param>
|
---|
| 891 | /// <returns>result</returns>
|
---|
| 892 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 893 | public static bool operator ==( complex A, float B) {
|
---|
| 894 | return (A.real == B && A.imag == 0.0);
|
---|
| 895 | }
|
---|
| 896 | /// <summary>
|
---|
| 897 | /// Unequality comparison for complex numbers
|
---|
| 898 | /// </summary>
|
---|
| 899 | /// <param name="A">Left side</param>
|
---|
| 900 | /// <param name="B">Right side</param>
|
---|
| 901 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 902 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 903 | public static bool operator !=( complex A, float B) {
|
---|
| 904 | return (A.imag != 0.0) || (A.real != B);
|
---|
| 905 | }
|
---|
| 906 | /// <summary>
|
---|
| 907 | /// Freater than comparison for complex numbers
|
---|
| 908 | /// </summary>
|
---|
| 909 | /// <param name="A">Left side</param>
|
---|
| 910 | /// <param name="B">Right side</param>
|
---|
| 911 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 912 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 913 | public static bool operator > ( complex A, float B) {
|
---|
| 914 | return (A.real > B);
|
---|
| 915 | }
|
---|
| 916 | /// <summary>
|
---|
| 917 | /// Lower than comparison for complex numbers
|
---|
| 918 | /// </summary>
|
---|
| 919 | /// <param name="A">Left side</param>
|
---|
| 920 | /// <param name="B">Right side</param>
|
---|
| 921 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 922 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 923 | public static bool operator <( complex A, float B) {
|
---|
| 924 | return (A.real < B);
|
---|
| 925 | }
|
---|
| 926 | /// <summary>
|
---|
| 927 | /// Greater than or equal to comparison for complex numbers
|
---|
| 928 | /// </summary>
|
---|
| 929 | /// <param name="A">Left side</param>
|
---|
| 930 | /// <param name="B">Right side</param>
|
---|
| 931 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 932 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 933 | public static bool operator >=( complex A, float B) {
|
---|
| 934 | return (A.real >= B);
|
---|
| 935 | }
|
---|
| 936 | /// <summary>
|
---|
| 937 | /// Lower than or equal to comparison for complex numbers
|
---|
| 938 | /// </summary>
|
---|
| 939 | /// <param name="A">Left side</param>
|
---|
| 940 | /// <param name="B">Right side</param>
|
---|
| 941 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 942 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 943 | public static bool operator <=( complex A, float B) {
|
---|
| 944 | return (A.real <= B);
|
---|
| 945 | }
|
---|
| 946 |
|
---|
| 947 | /// <summary>
|
---|
| 948 | /// Add two complex numbers
|
---|
| 949 | /// </summary>
|
---|
| 950 | /// <param name="A">First summand</param>
|
---|
| 951 | /// <param name="B">Second summand</param>
|
---|
| 952 | /// <returns>Result</returns>
|
---|
| 953 | public static complex operator +( complex A, byte B) {
|
---|
| 954 | complex ret;
|
---|
| 955 | ret.real = (double) (A.real + B);
|
---|
| 956 | ret.imag = (double) A.imag;
|
---|
| 957 | return ret;
|
---|
| 958 | }
|
---|
| 959 | /// <summary>
|
---|
| 960 | /// Subtract two values
|
---|
| 961 | /// </summary>
|
---|
| 962 | /// <param name="A">Minuend</param>
|
---|
| 963 | /// <param name="B">Subtrahend</param>
|
---|
| 964 | /// <returns>result</returns>
|
---|
| 965 | public static complex operator -( complex A, byte B) {
|
---|
| 966 | complex ret;
|
---|
| 967 | ret.real = (double) (A.real - B);
|
---|
| 968 | ret.imag = (double) A.imag;
|
---|
| 969 | return ret;
|
---|
| 970 | }
|
---|
| 971 | /// <summary>
|
---|
| 972 | /// Multiply two values
|
---|
| 973 | /// </summary>
|
---|
| 974 | /// <param name="A">First factor</param>
|
---|
| 975 | /// <param name="B">Second factor</param>
|
---|
| 976 | /// <returns>result</returns>
|
---|
| 977 | public static complex operator *( complex A, byte B) {
|
---|
| 978 | complex ret;
|
---|
| 979 | ret.real = (double) (A.real * B);
|
---|
| 980 | ret.imag = (double) (A.imag * B);
|
---|
| 981 | return ret;
|
---|
| 982 | }
|
---|
| 983 | /// <summary>
|
---|
| 984 | /// Divide two numbers
|
---|
| 985 | /// </summary>
|
---|
| 986 | /// <param name="A">Divident</param>
|
---|
| 987 | /// <param name="B">Divisor</param>
|
---|
| 988 | /// <returns>result</returns>
|
---|
| 989 | public static complex operator /( complex A, byte B) {
|
---|
| 990 | if (IsNaN(A)) return NaN;
|
---|
| 991 |
|
---|
| 992 | if (A.real == 0 && A.imag == 0) {
|
---|
| 993 | if (B == 0) return NaN;
|
---|
| 994 | return ( complex )0;
|
---|
| 995 | } else {
|
---|
| 996 | if (false)
|
---|
| 997 | {
|
---|
| 998 | if (IsInfinity(A)) {
|
---|
| 999 | return NaN;
|
---|
| 1000 | } else {
|
---|
| 1001 | return ( complex )0;
|
---|
| 1002 | }
|
---|
| 1003 | }
|
---|
| 1004 | }
|
---|
| 1005 | complex ret;
|
---|
| 1006 | if (B == 0) return INF ;
|
---|
| 1007 | ret.real = (double) (A.real / B);
|
---|
| 1008 | ret.imag = (double) (A.imag / B);
|
---|
| 1009 | return ret;
|
---|
| 1010 | }
|
---|
| 1011 | /// <summary>
|
---|
| 1012 | /// Equality comparison for complex numbers
|
---|
| 1013 | /// </summary>
|
---|
| 1014 | /// <param name="A">Left side</param>
|
---|
| 1015 | /// <param name="B">Right side</param>
|
---|
| 1016 | /// <returns>result</returns>
|
---|
| 1017 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1018 | public static bool operator ==( complex A, byte B) {
|
---|
| 1019 | return (A.real == B && A.imag == 0.0);
|
---|
| 1020 | }
|
---|
| 1021 | /// <summary>
|
---|
| 1022 | /// Unequality comparison for complex numbers
|
---|
| 1023 | /// </summary>
|
---|
| 1024 | /// <param name="A">Left side</param>
|
---|
| 1025 | /// <param name="B">Right side</param>
|
---|
| 1026 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 1027 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1028 | public static bool operator !=( complex A, byte B) {
|
---|
| 1029 | return (A.imag != 0.0) || (A.real != B);
|
---|
| 1030 | }
|
---|
| 1031 | /// <summary>
|
---|
| 1032 | /// Freater than comparison for complex numbers
|
---|
| 1033 | /// </summary>
|
---|
| 1034 | /// <param name="A">Left side</param>
|
---|
| 1035 | /// <param name="B">Right side</param>
|
---|
| 1036 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1037 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1038 | public static bool operator > ( complex A, byte B) {
|
---|
| 1039 | return (A.real > B);
|
---|
| 1040 | }
|
---|
| 1041 | /// <summary>
|
---|
| 1042 | /// Lower than comparison for complex numbers
|
---|
| 1043 | /// </summary>
|
---|
| 1044 | /// <param name="A">Left side</param>
|
---|
| 1045 | /// <param name="B">Right side</param>
|
---|
| 1046 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1047 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1048 | public static bool operator <( complex A, byte B) {
|
---|
| 1049 | return (A.real < B);
|
---|
| 1050 | }
|
---|
| 1051 | /// <summary>
|
---|
| 1052 | /// Greater than or equal to comparison for complex numbers
|
---|
| 1053 | /// </summary>
|
---|
| 1054 | /// <param name="A">Left side</param>
|
---|
| 1055 | /// <param name="B">Right side</param>
|
---|
| 1056 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1057 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1058 | public static bool operator >=( complex A, byte B) {
|
---|
| 1059 | return (A.real >= B);
|
---|
| 1060 | }
|
---|
| 1061 | /// <summary>
|
---|
| 1062 | /// Lower than or equal to comparison for complex numbers
|
---|
| 1063 | /// </summary>
|
---|
| 1064 | /// <param name="A">Left side</param>
|
---|
| 1065 | /// <param name="B">Right side</param>
|
---|
| 1066 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1067 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1068 | public static bool operator <=( complex A, byte B) {
|
---|
| 1069 | return (A.real <= B);
|
---|
| 1070 | }
|
---|
| 1071 |
|
---|
| 1072 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 1073 |
|
---|
| 1074 | |
---|
| 1075 |
|
---|
| 1076 | /// <summary>
|
---|
| 1077 | /// Add two complex values
|
---|
| 1078 | /// </summary>
|
---|
| 1079 | /// <param name="A">First summand</param>
|
---|
| 1080 | /// <param name="B">Second summand</param>
|
---|
| 1081 | /// <returns>Result</returns>
|
---|
| 1082 | public static complex operator +( double A, complex B) {
|
---|
| 1083 | complex ret;
|
---|
| 1084 | ret.real = (double) (A + B.real);
|
---|
| 1085 | ret.imag = (double) B.imag;
|
---|
| 1086 | return ret;
|
---|
| 1087 | }
|
---|
| 1088 | /// <summary>
|
---|
| 1089 | /// Subtract two values
|
---|
| 1090 | /// </summary>
|
---|
| 1091 | /// <param name="A">Minuend</param>
|
---|
| 1092 | /// <param name="B">Subtrahend</param>
|
---|
| 1093 | /// <returns>Result</returns>
|
---|
| 1094 | public static complex operator -( double A, complex B) {
|
---|
| 1095 | complex ret;
|
---|
| 1096 | ret.real = (double) (A - B.real);
|
---|
| 1097 | ret.imag = - (double) B.imag;
|
---|
| 1098 | return ret;
|
---|
| 1099 | }
|
---|
| 1100 | /// <summary>
|
---|
| 1101 | /// Multiply two values
|
---|
| 1102 | /// </summary>
|
---|
| 1103 | /// <param name="A">First factor</param>
|
---|
| 1104 | /// <param name="B">Second factor</param>
|
---|
| 1105 | /// <returns>Result</returns>
|
---|
| 1106 | public static complex operator *( double A, complex B) {
|
---|
| 1107 | complex ret;
|
---|
| 1108 | ret.real = (double) (A * B.real);
|
---|
| 1109 | ret.imag = (double) (A * B.imag);
|
---|
| 1110 | return ret;
|
---|
| 1111 | }
|
---|
| 1112 | /// <summary>
|
---|
| 1113 | /// Divide two values
|
---|
| 1114 | /// </summary>
|
---|
| 1115 | /// <param name="A">Divident</param>
|
---|
| 1116 | /// <param name="B">Divisor</param>
|
---|
| 1117 | /// <returns>Result</returns>
|
---|
| 1118 | public static complex operator /( double A, complex B) {
|
---|
| 1119 | complex ret;
|
---|
| 1120 | if (A == 0) {
|
---|
| 1121 | if (IsInfinity(B)) return NaN;
|
---|
| 1122 | } else {
|
---|
| 1123 | if (IsInfinity(B)) return ( complex )0;
|
---|
| 1124 | }
|
---|
| 1125 | if (B.real == 0 && B.imag == 0) {
|
---|
| 1126 | return INF;
|
---|
| 1127 | }
|
---|
| 1128 | // this algorithm is taken from [1]. The one described in [2] was not taken. Tests
|
---|
| 1129 | // did not show any advantage when using double precision floating point arithmetic.
|
---|
| 1130 | double tmp;
|
---|
| 1131 | if (Math.Abs(B.real) >= Math.Abs(B.imag)) {
|
---|
| 1132 | tmp = (double) (B.imag * (1/B.real));
|
---|
| 1133 | ret.imag = (double) (B.real + B.imag*tmp);
|
---|
| 1134 | ret.real = (double) A/ret.imag;
|
---|
| 1135 | ret.imag = - (double) (A*tmp)/ret.imag;
|
---|
| 1136 | } else {
|
---|
| 1137 | tmp = (double) (B.real * (1/B.imag));
|
---|
| 1138 | ret.imag = (double) (B.imag + B.real*tmp);
|
---|
| 1139 | ret.real = (double) (A*tmp)/ret.imag;
|
---|
| 1140 | ret.imag = - (double) A/ret.imag;
|
---|
| 1141 | }
|
---|
| 1142 | return ret;
|
---|
| 1143 | }
|
---|
| 1144 | /// <summary>
|
---|
| 1145 | /// Equality comparison for complex numbers
|
---|
| 1146 | /// </summary>
|
---|
| 1147 | /// <param name="A">Left side</param>
|
---|
| 1148 | /// <param name="B">Right side</param>
|
---|
| 1149 | /// <returns>Result</returns>
|
---|
| 1150 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1151 | public static bool operator ==( double A, complex B) {
|
---|
| 1152 | return (B.real == A && B.imag == 0.0);
|
---|
| 1153 | }
|
---|
| 1154 | /// <summary>
|
---|
| 1155 | /// Unequality comparison for complex numbers
|
---|
| 1156 | /// </summary>
|
---|
| 1157 | /// <param name="A">Left side</param>
|
---|
| 1158 | /// <param name="B">Right side</param>
|
---|
| 1159 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 1160 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1161 | public static bool operator !=( double A, complex B) {
|
---|
| 1162 | return (B.imag != 0.0) || (B.real != A);
|
---|
| 1163 | }
|
---|
| 1164 | /// <summary>
|
---|
| 1165 | /// Greater than comparison for complex numbers
|
---|
| 1166 | /// </summary>
|
---|
| 1167 | /// <param name="A">Left side</param>
|
---|
| 1168 | /// <param name="B">Right side</param>
|
---|
| 1169 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1170 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1171 | public static bool operator > ( double A, complex B) {
|
---|
| 1172 | return (A > B.real);
|
---|
| 1173 | }
|
---|
| 1174 | /// <summary>
|
---|
| 1175 | /// Lower than comparison for complex numbers
|
---|
| 1176 | /// </summary>
|
---|
| 1177 | /// <param name="A">Left side</param>
|
---|
| 1178 | /// <param name="B">Right side</param>
|
---|
| 1179 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1180 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1181 | public static bool operator < ( double A, complex B) {
|
---|
| 1182 | return (A < B.real);
|
---|
| 1183 | }
|
---|
| 1184 | /// <summary>
|
---|
| 1185 | /// Greater than or equal to comparison for complex numbers
|
---|
| 1186 | /// </summary>
|
---|
| 1187 | /// <param name="A">Left side</param>
|
---|
| 1188 | /// <param name="B">Right side</param>
|
---|
| 1189 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1190 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1191 | public static bool operator >=( double A, complex B) {
|
---|
| 1192 | return (A >= B.real);
|
---|
| 1193 | }
|
---|
| 1194 | /// <summary>
|
---|
| 1195 | /// Lower than or equal to comparison for complex numbers
|
---|
| 1196 | /// </summary>
|
---|
| 1197 | /// <param name="A">Left side</param>
|
---|
| 1198 | /// <param name="B">Right side</param>
|
---|
| 1199 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1200 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1201 | public static bool operator <=( double A, complex B) {
|
---|
| 1202 | return (A <= B.real);
|
---|
| 1203 | }
|
---|
| 1204 | |
---|
| 1205 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 1206 | |
---|
| 1207 |
|
---|
| 1208 | /// <summary>
|
---|
| 1209 | /// Add two complex values
|
---|
| 1210 | /// </summary>
|
---|
| 1211 | /// <param name="A">First summand</param>
|
---|
| 1212 | /// <param name="B">Second summand</param>
|
---|
| 1213 | /// <returns>Result</returns>
|
---|
| 1214 | public static complex operator +( Int64 A, complex B) {
|
---|
| 1215 | complex ret;
|
---|
| 1216 | ret.real = (double) (A + B.real);
|
---|
| 1217 | ret.imag = (double) B.imag;
|
---|
| 1218 | return ret;
|
---|
| 1219 | }
|
---|
| 1220 | /// <summary>
|
---|
| 1221 | /// Subtract two values
|
---|
| 1222 | /// </summary>
|
---|
| 1223 | /// <param name="A">Minuend</param>
|
---|
| 1224 | /// <param name="B">Subtrahend</param>
|
---|
| 1225 | /// <returns>Result</returns>
|
---|
| 1226 | public static complex operator -( Int64 A, complex B) {
|
---|
| 1227 | complex ret;
|
---|
| 1228 | ret.real = (double) (A - B.real);
|
---|
| 1229 | ret.imag = - (double) B.imag;
|
---|
| 1230 | return ret;
|
---|
| 1231 | }
|
---|
| 1232 | /// <summary>
|
---|
| 1233 | /// Multiply two values
|
---|
| 1234 | /// </summary>
|
---|
| 1235 | /// <param name="A">First factor</param>
|
---|
| 1236 | /// <param name="B">Second factor</param>
|
---|
| 1237 | /// <returns>Result</returns>
|
---|
| 1238 | public static complex operator *( Int64 A, complex B) {
|
---|
| 1239 | complex ret;
|
---|
| 1240 | ret.real = (double) (A * B.real);
|
---|
| 1241 | ret.imag = (double) (A * B.imag);
|
---|
| 1242 | return ret;
|
---|
| 1243 | }
|
---|
| 1244 | /// <summary>
|
---|
| 1245 | /// Divide two values
|
---|
| 1246 | /// </summary>
|
---|
| 1247 | /// <param name="A">Divident</param>
|
---|
| 1248 | /// <param name="B">Divisor</param>
|
---|
| 1249 | /// <returns>Result</returns>
|
---|
| 1250 | public static complex operator /( Int64 A, complex B) {
|
---|
| 1251 | complex ret;
|
---|
| 1252 | if (A == 0) {
|
---|
| 1253 | if (IsInfinity(B)) return NaN;
|
---|
| 1254 | } else {
|
---|
| 1255 | if (IsInfinity(B)) return ( complex )0;
|
---|
| 1256 | }
|
---|
| 1257 | if (B.real == 0 && B.imag == 0) {
|
---|
| 1258 | return INF;
|
---|
| 1259 | }
|
---|
| 1260 | // this algorithm is taken from [1]. The one described in [2] was not taken. Tests
|
---|
| 1261 | // did not show any advantage when using double precision floating point arithmetic.
|
---|
| 1262 | double tmp;
|
---|
| 1263 | if (Math.Abs(B.real) >= Math.Abs(B.imag)) {
|
---|
| 1264 | tmp = (double) (B.imag * (1/B.real));
|
---|
| 1265 | ret.imag = (double) (B.real + B.imag*tmp);
|
---|
| 1266 | ret.real = (double) A/ret.imag;
|
---|
| 1267 | ret.imag = - (double) (A*tmp)/ret.imag;
|
---|
| 1268 | } else {
|
---|
| 1269 | tmp = (double) (B.real * (1/B.imag));
|
---|
| 1270 | ret.imag = (double) (B.imag + B.real*tmp);
|
---|
| 1271 | ret.real = (double) (A*tmp)/ret.imag;
|
---|
| 1272 | ret.imag = - (double) A/ret.imag;
|
---|
| 1273 | }
|
---|
| 1274 | return ret;
|
---|
| 1275 | }
|
---|
| 1276 | /// <summary>
|
---|
| 1277 | /// Equality comparison for complex numbers
|
---|
| 1278 | /// </summary>
|
---|
| 1279 | /// <param name="A">Left side</param>
|
---|
| 1280 | /// <param name="B">Right side</param>
|
---|
| 1281 | /// <returns>Result</returns>
|
---|
| 1282 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1283 | public static bool operator ==( Int64 A, complex B) {
|
---|
| 1284 | return (B.real == A && B.imag == 0.0);
|
---|
| 1285 | }
|
---|
| 1286 | /// <summary>
|
---|
| 1287 | /// Unequality comparison for complex numbers
|
---|
| 1288 | /// </summary>
|
---|
| 1289 | /// <param name="A">Left side</param>
|
---|
| 1290 | /// <param name="B">Right side</param>
|
---|
| 1291 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 1292 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1293 | public static bool operator !=( Int64 A, complex B) {
|
---|
| 1294 | return (B.imag != 0.0) || (B.real != A);
|
---|
| 1295 | }
|
---|
| 1296 | /// <summary>
|
---|
| 1297 | /// Greater than comparison for complex numbers
|
---|
| 1298 | /// </summary>
|
---|
| 1299 | /// <param name="A">Left side</param>
|
---|
| 1300 | /// <param name="B">Right side</param>
|
---|
| 1301 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1302 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1303 | public static bool operator > ( Int64 A, complex B) {
|
---|
| 1304 | return (A > B.real);
|
---|
| 1305 | }
|
---|
| 1306 | /// <summary>
|
---|
| 1307 | /// Lower than comparison for complex numbers
|
---|
| 1308 | /// </summary>
|
---|
| 1309 | /// <param name="A">Left side</param>
|
---|
| 1310 | /// <param name="B">Right side</param>
|
---|
| 1311 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1312 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1313 | public static bool operator < ( Int64 A, complex B) {
|
---|
| 1314 | return (A < B.real);
|
---|
| 1315 | }
|
---|
| 1316 | /// <summary>
|
---|
| 1317 | /// Greater than or equal to comparison for complex numbers
|
---|
| 1318 | /// </summary>
|
---|
| 1319 | /// <param name="A">Left side</param>
|
---|
| 1320 | /// <param name="B">Right side</param>
|
---|
| 1321 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1322 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1323 | public static bool operator >=( Int64 A, complex B) {
|
---|
| 1324 | return (A >= B.real);
|
---|
| 1325 | }
|
---|
| 1326 | /// <summary>
|
---|
| 1327 | /// Lower than or equal to comparison for complex numbers
|
---|
| 1328 | /// </summary>
|
---|
| 1329 | /// <param name="A">Left side</param>
|
---|
| 1330 | /// <param name="B">Right side</param>
|
---|
| 1331 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1332 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1333 | public static bool operator <=( Int64 A, complex B) {
|
---|
| 1334 | return (A <= B.real);
|
---|
| 1335 | }
|
---|
| 1336 |
|
---|
| 1337 | /// <summary>
|
---|
| 1338 | /// Add two complex values
|
---|
| 1339 | /// </summary>
|
---|
| 1340 | /// <param name="A">First summand</param>
|
---|
| 1341 | /// <param name="B">Second summand</param>
|
---|
| 1342 | /// <returns>Result</returns>
|
---|
| 1343 | public static complex operator +( Int32 A, complex B) {
|
---|
| 1344 | complex ret;
|
---|
| 1345 | ret.real = (double) (A + B.real);
|
---|
| 1346 | ret.imag = (double) B.imag;
|
---|
| 1347 | return ret;
|
---|
| 1348 | }
|
---|
| 1349 | /// <summary>
|
---|
| 1350 | /// Subtract two values
|
---|
| 1351 | /// </summary>
|
---|
| 1352 | /// <param name="A">Minuend</param>
|
---|
| 1353 | /// <param name="B">Subtrahend</param>
|
---|
| 1354 | /// <returns>Result</returns>
|
---|
| 1355 | public static complex operator -( Int32 A, complex B) {
|
---|
| 1356 | complex ret;
|
---|
| 1357 | ret.real = (double) (A - B.real);
|
---|
| 1358 | ret.imag = - (double) B.imag;
|
---|
| 1359 | return ret;
|
---|
| 1360 | }
|
---|
| 1361 | /// <summary>
|
---|
| 1362 | /// Multiply two values
|
---|
| 1363 | /// </summary>
|
---|
| 1364 | /// <param name="A">First factor</param>
|
---|
| 1365 | /// <param name="B">Second factor</param>
|
---|
| 1366 | /// <returns>Result</returns>
|
---|
| 1367 | public static complex operator *( Int32 A, complex B) {
|
---|
| 1368 | complex ret;
|
---|
| 1369 | ret.real = (double) (A * B.real);
|
---|
| 1370 | ret.imag = (double) (A * B.imag);
|
---|
| 1371 | return ret;
|
---|
| 1372 | }
|
---|
| 1373 | /// <summary>
|
---|
| 1374 | /// Divide two values
|
---|
| 1375 | /// </summary>
|
---|
| 1376 | /// <param name="A">Divident</param>
|
---|
| 1377 | /// <param name="B">Divisor</param>
|
---|
| 1378 | /// <returns>Result</returns>
|
---|
| 1379 | public static complex operator /( Int32 A, complex B) {
|
---|
| 1380 | complex ret;
|
---|
| 1381 | if (A == 0) {
|
---|
| 1382 | if (IsInfinity(B)) return NaN;
|
---|
| 1383 | } else {
|
---|
| 1384 | if (IsInfinity(B)) return ( complex )0;
|
---|
| 1385 | }
|
---|
| 1386 | if (B.real == 0 && B.imag == 0) {
|
---|
| 1387 | return INF;
|
---|
| 1388 | }
|
---|
| 1389 | // this algorithm is taken from [1]. The one described in [2] was not taken. Tests
|
---|
| 1390 | // did not show any advantage when using double precision floating point arithmetic.
|
---|
| 1391 | double tmp;
|
---|
| 1392 | if (Math.Abs(B.real) >= Math.Abs(B.imag)) {
|
---|
| 1393 | tmp = (double) (B.imag * (1/B.real));
|
---|
| 1394 | ret.imag = (double) (B.real + B.imag*tmp);
|
---|
| 1395 | ret.real = (double) A/ret.imag;
|
---|
| 1396 | ret.imag = - (double) (A*tmp)/ret.imag;
|
---|
| 1397 | } else {
|
---|
| 1398 | tmp = (double) (B.real * (1/B.imag));
|
---|
| 1399 | ret.imag = (double) (B.imag + B.real*tmp);
|
---|
| 1400 | ret.real = (double) (A*tmp)/ret.imag;
|
---|
| 1401 | ret.imag = - (double) A/ret.imag;
|
---|
| 1402 | }
|
---|
| 1403 | return ret;
|
---|
| 1404 | }
|
---|
| 1405 | /// <summary>
|
---|
| 1406 | /// Equality comparison for complex numbers
|
---|
| 1407 | /// </summary>
|
---|
| 1408 | /// <param name="A">Left side</param>
|
---|
| 1409 | /// <param name="B">Right side</param>
|
---|
| 1410 | /// <returns>Result</returns>
|
---|
| 1411 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1412 | public static bool operator ==( Int32 A, complex B) {
|
---|
| 1413 | return (B.real == A && B.imag == 0.0);
|
---|
| 1414 | }
|
---|
| 1415 | /// <summary>
|
---|
| 1416 | /// Unequality comparison for complex numbers
|
---|
| 1417 | /// </summary>
|
---|
| 1418 | /// <param name="A">Left side</param>
|
---|
| 1419 | /// <param name="B">Right side</param>
|
---|
| 1420 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 1421 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1422 | public static bool operator !=( Int32 A, complex B) {
|
---|
| 1423 | return (B.imag != 0.0) || (B.real != A);
|
---|
| 1424 | }
|
---|
| 1425 | /// <summary>
|
---|
| 1426 | /// Greater than comparison for complex numbers
|
---|
| 1427 | /// </summary>
|
---|
| 1428 | /// <param name="A">Left side</param>
|
---|
| 1429 | /// <param name="B">Right side</param>
|
---|
| 1430 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1431 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1432 | public static bool operator > ( Int32 A, complex B) {
|
---|
| 1433 | return (A > B.real);
|
---|
| 1434 | }
|
---|
| 1435 | /// <summary>
|
---|
| 1436 | /// Lower than comparison for complex numbers
|
---|
| 1437 | /// </summary>
|
---|
| 1438 | /// <param name="A">Left side</param>
|
---|
| 1439 | /// <param name="B">Right side</param>
|
---|
| 1440 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1441 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1442 | public static bool operator < ( Int32 A, complex B) {
|
---|
| 1443 | return (A < B.real);
|
---|
| 1444 | }
|
---|
| 1445 | /// <summary>
|
---|
| 1446 | /// Greater than or equal to comparison for complex numbers
|
---|
| 1447 | /// </summary>
|
---|
| 1448 | /// <param name="A">Left side</param>
|
---|
| 1449 | /// <param name="B">Right side</param>
|
---|
| 1450 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1451 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1452 | public static bool operator >=( Int32 A, complex B) {
|
---|
| 1453 | return (A >= B.real);
|
---|
| 1454 | }
|
---|
| 1455 | /// <summary>
|
---|
| 1456 | /// Lower than or equal to comparison for complex numbers
|
---|
| 1457 | /// </summary>
|
---|
| 1458 | /// <param name="A">Left side</param>
|
---|
| 1459 | /// <param name="B">Right side</param>
|
---|
| 1460 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1461 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1462 | public static bool operator <=( Int32 A, complex B) {
|
---|
| 1463 | return (A <= B.real);
|
---|
| 1464 | }
|
---|
| 1465 |
|
---|
| 1466 | /// <summary>
|
---|
| 1467 | /// Add two complex values
|
---|
| 1468 | /// </summary>
|
---|
| 1469 | /// <param name="A">First summand</param>
|
---|
| 1470 | /// <param name="B">Second summand</param>
|
---|
| 1471 | /// <returns>Result</returns>
|
---|
| 1472 | public static complex operator +( float A, complex B) {
|
---|
| 1473 | complex ret;
|
---|
| 1474 | ret.real = (double) (A + B.real);
|
---|
| 1475 | ret.imag = (double) B.imag;
|
---|
| 1476 | return ret;
|
---|
| 1477 | }
|
---|
| 1478 | /// <summary>
|
---|
| 1479 | /// Subtract two values
|
---|
| 1480 | /// </summary>
|
---|
| 1481 | /// <param name="A">Minuend</param>
|
---|
| 1482 | /// <param name="B">Subtrahend</param>
|
---|
| 1483 | /// <returns>Result</returns>
|
---|
| 1484 | public static complex operator -( float A, complex B) {
|
---|
| 1485 | complex ret;
|
---|
| 1486 | ret.real = (double) (A - B.real);
|
---|
| 1487 | ret.imag = - (double) B.imag;
|
---|
| 1488 | return ret;
|
---|
| 1489 | }
|
---|
| 1490 | /// <summary>
|
---|
| 1491 | /// Multiply two values
|
---|
| 1492 | /// </summary>
|
---|
| 1493 | /// <param name="A">First factor</param>
|
---|
| 1494 | /// <param name="B">Second factor</param>
|
---|
| 1495 | /// <returns>Result</returns>
|
---|
| 1496 | public static complex operator *( float A, complex B) {
|
---|
| 1497 | complex ret;
|
---|
| 1498 | ret.real = (double) (A * B.real);
|
---|
| 1499 | ret.imag = (double) (A * B.imag);
|
---|
| 1500 | return ret;
|
---|
| 1501 | }
|
---|
| 1502 | /// <summary>
|
---|
| 1503 | /// Divide two values
|
---|
| 1504 | /// </summary>
|
---|
| 1505 | /// <param name="A">Divident</param>
|
---|
| 1506 | /// <param name="B">Divisor</param>
|
---|
| 1507 | /// <returns>Result</returns>
|
---|
| 1508 | public static complex operator /( float A, complex B) {
|
---|
| 1509 | complex ret;
|
---|
| 1510 | if (A == 0) {
|
---|
| 1511 | if (IsInfinity(B)) return NaN;
|
---|
| 1512 | } else {
|
---|
| 1513 | if (IsInfinity(B)) return ( complex )0;
|
---|
| 1514 | }
|
---|
| 1515 | if (B.real == 0 && B.imag == 0) {
|
---|
| 1516 | return INF;
|
---|
| 1517 | }
|
---|
| 1518 | // this algorithm is taken from [1]. The one described in [2] was not taken. Tests
|
---|
| 1519 | // did not show any advantage when using double precision floating point arithmetic.
|
---|
| 1520 | double tmp;
|
---|
| 1521 | if (Math.Abs(B.real) >= Math.Abs(B.imag)) {
|
---|
| 1522 | tmp = (double) (B.imag * (1/B.real));
|
---|
| 1523 | ret.imag = (double) (B.real + B.imag*tmp);
|
---|
| 1524 | ret.real = (double) A/ret.imag;
|
---|
| 1525 | ret.imag = - (double) (A*tmp)/ret.imag;
|
---|
| 1526 | } else {
|
---|
| 1527 | tmp = (double) (B.real * (1/B.imag));
|
---|
| 1528 | ret.imag = (double) (B.imag + B.real*tmp);
|
---|
| 1529 | ret.real = (double) (A*tmp)/ret.imag;
|
---|
| 1530 | ret.imag = - (double) A/ret.imag;
|
---|
| 1531 | }
|
---|
| 1532 | return ret;
|
---|
| 1533 | }
|
---|
| 1534 | /// <summary>
|
---|
| 1535 | /// Equality comparison for complex numbers
|
---|
| 1536 | /// </summary>
|
---|
| 1537 | /// <param name="A">Left side</param>
|
---|
| 1538 | /// <param name="B">Right side</param>
|
---|
| 1539 | /// <returns>Result</returns>
|
---|
| 1540 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1541 | public static bool operator ==( float A, complex B) {
|
---|
| 1542 | return (B.real == A && B.imag == 0.0);
|
---|
| 1543 | }
|
---|
| 1544 | /// <summary>
|
---|
| 1545 | /// Unequality comparison for complex numbers
|
---|
| 1546 | /// </summary>
|
---|
| 1547 | /// <param name="A">Left side</param>
|
---|
| 1548 | /// <param name="B">Right side</param>
|
---|
| 1549 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 1550 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1551 | public static bool operator !=( float A, complex B) {
|
---|
| 1552 | return (B.imag != 0.0) || (B.real != A);
|
---|
| 1553 | }
|
---|
| 1554 | /// <summary>
|
---|
| 1555 | /// Greater than comparison for complex numbers
|
---|
| 1556 | /// </summary>
|
---|
| 1557 | /// <param name="A">Left side</param>
|
---|
| 1558 | /// <param name="B">Right side</param>
|
---|
| 1559 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1560 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1561 | public static bool operator > ( float A, complex B) {
|
---|
| 1562 | return (A > B.real);
|
---|
| 1563 | }
|
---|
| 1564 | /// <summary>
|
---|
| 1565 | /// Lower than comparison for complex numbers
|
---|
| 1566 | /// </summary>
|
---|
| 1567 | /// <param name="A">Left side</param>
|
---|
| 1568 | /// <param name="B">Right side</param>
|
---|
| 1569 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1570 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1571 | public static bool operator < ( float A, complex B) {
|
---|
| 1572 | return (A < B.real);
|
---|
| 1573 | }
|
---|
| 1574 | /// <summary>
|
---|
| 1575 | /// Greater than or equal to comparison for complex numbers
|
---|
| 1576 | /// </summary>
|
---|
| 1577 | /// <param name="A">Left side</param>
|
---|
| 1578 | /// <param name="B">Right side</param>
|
---|
| 1579 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1580 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1581 | public static bool operator >=( float A, complex B) {
|
---|
| 1582 | return (A >= B.real);
|
---|
| 1583 | }
|
---|
| 1584 | /// <summary>
|
---|
| 1585 | /// Lower than or equal to comparison for complex numbers
|
---|
| 1586 | /// </summary>
|
---|
| 1587 | /// <param name="A">Left side</param>
|
---|
| 1588 | /// <param name="B">Right side</param>
|
---|
| 1589 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1590 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1591 | public static bool operator <=( float A, complex B) {
|
---|
| 1592 | return (A <= B.real);
|
---|
| 1593 | }
|
---|
| 1594 |
|
---|
| 1595 | /// <summary>
|
---|
| 1596 | /// Add two complex values
|
---|
| 1597 | /// </summary>
|
---|
| 1598 | /// <param name="A">First summand</param>
|
---|
| 1599 | /// <param name="B">Second summand</param>
|
---|
| 1600 | /// <returns>Result</returns>
|
---|
| 1601 | public static complex operator +( byte A, complex B) {
|
---|
| 1602 | complex ret;
|
---|
| 1603 | ret.real = (double) (A + B.real);
|
---|
| 1604 | ret.imag = (double) B.imag;
|
---|
| 1605 | return ret;
|
---|
| 1606 | }
|
---|
| 1607 | /// <summary>
|
---|
| 1608 | /// Subtract two values
|
---|
| 1609 | /// </summary>
|
---|
| 1610 | /// <param name="A">Minuend</param>
|
---|
| 1611 | /// <param name="B">Subtrahend</param>
|
---|
| 1612 | /// <returns>Result</returns>
|
---|
| 1613 | public static complex operator -( byte A, complex B) {
|
---|
| 1614 | complex ret;
|
---|
| 1615 | ret.real = (double) (A - B.real);
|
---|
| 1616 | ret.imag = - (double) B.imag;
|
---|
| 1617 | return ret;
|
---|
| 1618 | }
|
---|
| 1619 | /// <summary>
|
---|
| 1620 | /// Multiply two values
|
---|
| 1621 | /// </summary>
|
---|
| 1622 | /// <param name="A">First factor</param>
|
---|
| 1623 | /// <param name="B">Second factor</param>
|
---|
| 1624 | /// <returns>Result</returns>
|
---|
| 1625 | public static complex operator *( byte A, complex B) {
|
---|
| 1626 | complex ret;
|
---|
| 1627 | ret.real = (double) (A * B.real);
|
---|
| 1628 | ret.imag = (double) (A * B.imag);
|
---|
| 1629 | return ret;
|
---|
| 1630 | }
|
---|
| 1631 | /// <summary>
|
---|
| 1632 | /// Divide two values
|
---|
| 1633 | /// </summary>
|
---|
| 1634 | /// <param name="A">Divident</param>
|
---|
| 1635 | /// <param name="B">Divisor</param>
|
---|
| 1636 | /// <returns>Result</returns>
|
---|
| 1637 | public static complex operator /( byte A, complex B) {
|
---|
| 1638 | complex ret;
|
---|
| 1639 | if (A == 0) {
|
---|
| 1640 | if (IsInfinity(B)) return NaN;
|
---|
| 1641 | } else {
|
---|
| 1642 | if (IsInfinity(B)) return ( complex )0;
|
---|
| 1643 | }
|
---|
| 1644 | if (B.real == 0 && B.imag == 0) {
|
---|
| 1645 | return INF;
|
---|
| 1646 | }
|
---|
| 1647 | // this algorithm is taken from [1]. The one described in [2] was not taken. Tests
|
---|
| 1648 | // did not show any advantage when using double precision floating point arithmetic.
|
---|
| 1649 | double tmp;
|
---|
| 1650 | if (Math.Abs(B.real) >= Math.Abs(B.imag)) {
|
---|
| 1651 | tmp = (double) (B.imag * (1/B.real));
|
---|
| 1652 | ret.imag = (double) (B.real + B.imag*tmp);
|
---|
| 1653 | ret.real = (double) A/ret.imag;
|
---|
| 1654 | ret.imag = - (double) (A*tmp)/ret.imag;
|
---|
| 1655 | } else {
|
---|
| 1656 | tmp = (double) (B.real * (1/B.imag));
|
---|
| 1657 | ret.imag = (double) (B.imag + B.real*tmp);
|
---|
| 1658 | ret.real = (double) (A*tmp)/ret.imag;
|
---|
| 1659 | ret.imag = - (double) A/ret.imag;
|
---|
| 1660 | }
|
---|
| 1661 | return ret;
|
---|
| 1662 | }
|
---|
| 1663 | /// <summary>
|
---|
| 1664 | /// Equality comparison for complex numbers
|
---|
| 1665 | /// </summary>
|
---|
| 1666 | /// <param name="A">Left side</param>
|
---|
| 1667 | /// <param name="B">Right side</param>
|
---|
| 1668 | /// <returns>Result</returns>
|
---|
| 1669 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1670 | public static bool operator ==( byte A, complex B) {
|
---|
| 1671 | return (B.real == A && B.imag == 0.0);
|
---|
| 1672 | }
|
---|
| 1673 | /// <summary>
|
---|
| 1674 | /// Unequality comparison for complex numbers
|
---|
| 1675 | /// </summary>
|
---|
| 1676 | /// <param name="A">Left side</param>
|
---|
| 1677 | /// <param name="B">Right side</param>
|
---|
| 1678 | /// <returns>true if real and imaginary parts of A and B are not equal, false otherwise</returns>
|
---|
| 1679 | /// <remarks>Real inputs are converted to a complex number and the result is compared to the complex input.</remarks>
|
---|
| 1680 | public static bool operator !=( byte A, complex B) {
|
---|
| 1681 | return (B.imag != 0.0) || (B.real != A);
|
---|
| 1682 | }
|
---|
| 1683 | /// <summary>
|
---|
| 1684 | /// Greater than comparison for complex numbers
|
---|
| 1685 | /// </summary>
|
---|
| 1686 | /// <param name="A">Left side</param>
|
---|
| 1687 | /// <param name="B">Right side</param>
|
---|
| 1688 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1689 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1690 | public static bool operator > ( byte A, complex B) {
|
---|
| 1691 | return (A > B.real);
|
---|
| 1692 | }
|
---|
| 1693 | /// <summary>
|
---|
| 1694 | /// Lower than comparison for complex numbers
|
---|
| 1695 | /// </summary>
|
---|
| 1696 | /// <param name="A">Left side</param>
|
---|
| 1697 | /// <param name="B">Right side</param>
|
---|
| 1698 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1699 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1700 | public static bool operator < ( byte A, complex B) {
|
---|
| 1701 | return (A < B.real);
|
---|
| 1702 | }
|
---|
| 1703 | /// <summary>
|
---|
| 1704 | /// Greater than or equal to comparison for complex numbers
|
---|
| 1705 | /// </summary>
|
---|
| 1706 | /// <param name="A">Left side</param>
|
---|
| 1707 | /// <param name="B">Right side</param>
|
---|
| 1708 | /// <returns>true if real part of A is greater than real part of B, false otherwise</returns>
|
---|
| 1709 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1710 | public static bool operator >=( byte A, complex B) {
|
---|
| 1711 | return (A >= B.real);
|
---|
| 1712 | }
|
---|
| 1713 | /// <summary>
|
---|
| 1714 | /// Lower than or equal to comparison for complex numbers
|
---|
| 1715 | /// </summary>
|
---|
| 1716 | /// <param name="A">Left side</param>
|
---|
| 1717 | /// <param name="B">Right side</param>
|
---|
| 1718 | /// <returns>true if real part of A is lower then real part of B, false otherwise</returns>
|
---|
| 1719 | /// <remarks>Only the real parts are compared!</remarks>
|
---|
| 1720 | public static bool operator <=( byte A, complex B) {
|
---|
| 1721 | return (A <= B.real);
|
---|
| 1722 | }
|
---|
| 1723 |
|
---|
| 1724 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 1725 |
|
---|
| 1726 | #region unary minus
|
---|
| 1727 | /// <summary>
|
---|
| 1728 | /// Unary minus operator
|
---|
| 1729 | /// </summary>
|
---|
| 1730 | /// <param name="A">Complex input</param>
|
---|
| 1731 | /// <returns>Complex number similar to A, having real and imag part negated</returns>
|
---|
| 1732 | public static complex operator -( complex A) {
|
---|
| 1733 | complex ret = new complex();
|
---|
| 1734 | ret.imag = -A.imag;
|
---|
| 1735 | ret.real = -A.real;
|
---|
| 1736 | return ret;
|
---|
| 1737 | }
|
---|
| 1738 | #endregion
|
---|
| 1739 |
|
---|
| 1740 | #region CAST_OPERATORS
|
---|
| 1741 | /// <summary>
|
---|
| 1742 | /// Cast value to complex number
|
---|
| 1743 | /// </summary>
|
---|
| 1744 | /// <param name="a">Value to cast</param>
|
---|
| 1745 | /// <returns>Complex number with the real part having the same value as a and the imaginary part is 0.</returns>
|
---|
| 1746 | public static implicit operator complex(double a) {
|
---|
| 1747 | return new complex(a, 0.0);
|
---|
| 1748 | }
|
---|
| 1749 | /// <summary>
|
---|
| 1750 | /// Cast value to complex number
|
---|
| 1751 | /// </summary>
|
---|
| 1752 | /// <param name="a">Value to cast</param>
|
---|
| 1753 | /// <returns>Complex number with the real part having the same value as the a and the imaginary part is 0.</returns>
|
---|
| 1754 | public static implicit operator complex(float a) {
|
---|
| 1755 | return new complex(a, 0.0);
|
---|
| 1756 | }
|
---|
| 1757 | /// <summary>
|
---|
| 1758 | /// Cast value to complex number
|
---|
| 1759 | /// </summary>
|
---|
| 1760 | /// <param name="a">Value to cast</param>
|
---|
| 1761 | /// <returns>Complex number being a copy of the real and imaginary parts of a.</returns>
|
---|
| 1762 | public static implicit operator complex(fcomplex a) {
|
---|
| 1763 | return new complex(a.real, a.imag);
|
---|
| 1764 | }
|
---|
| 1765 | /// <summary>
|
---|
| 1766 | /// Cast value to complex number
|
---|
| 1767 | /// </summary>
|
---|
| 1768 | /// <param name="a">Value to cast</param>
|
---|
| 1769 | /// <returns>Complex number with the real part having the same value as a and the imaginary part is 0.</returns>
|
---|
| 1770 | public static implicit operator complex(byte a) {
|
---|
| 1771 | return new complex(a, 0.0);
|
---|
| 1772 | }
|
---|
| 1773 | /// <summary>
|
---|
| 1774 | /// Cast value to complex number
|
---|
| 1775 | /// </summary>
|
---|
| 1776 | /// <param name="a">Value to cast</param>
|
---|
| 1777 | /// <returns>Complex number with the real part having the same value as a and the imaginary part is 0.</returns>
|
---|
| 1778 | public static implicit operator complex(Int32 a) {
|
---|
| 1779 | return new complex(a, 0.0);
|
---|
| 1780 | }
|
---|
| 1781 | /// <summary>
|
---|
| 1782 | /// Cast value to complex number
|
---|
| 1783 | /// </summary>
|
---|
| 1784 | /// <param name="a">Value to cast</param>
|
---|
| 1785 | /// <returns>Complex number with the real part having the same value as a and the imaginary part is 0.</returns>
|
---|
| 1786 | public static implicit operator complex(Int64 a) {
|
---|
| 1787 | return new complex(a, 0.0);
|
---|
| 1788 | }
|
---|
| 1789 |
|
---|
| 1790 | /// <summary>
|
---|
| 1791 | /// Cast value from complex number
|
---|
| 1792 | /// </summary>
|
---|
| 1793 | /// <param name="a">Complex value to cast</param>
|
---|
| 1794 | /// <returns>Double number with the real part of a </returns>
|
---|
| 1795 | public static explicit operator double(complex a) {
|
---|
| 1796 | return a.real;
|
---|
| 1797 | }
|
---|
| 1798 | /// <summary>
|
---|
| 1799 | /// Cast value from complex number
|
---|
| 1800 | /// </summary>
|
---|
| 1801 | /// <param name="a">Complex value to cast</param>
|
---|
| 1802 | /// <returns>number with the real part of a </returns>
|
---|
| 1803 | /// <remarks>the return value is the result of a cast from double to float.</remarks>
|
---|
| 1804 | public static explicit operator float(complex a) {
|
---|
| 1805 | return (float)a.real;
|
---|
| 1806 | }
|
---|
| 1807 | /// <summary>
|
---|
| 1808 | /// Cast value from complex number
|
---|
| 1809 | /// </summary>
|
---|
| 1810 | /// <param name="a">Complex value to cast</param>
|
---|
| 1811 | /// <returns>float complex number with the real and imaginary parts being a copy of a </returns>
|
---|
| 1812 | /// <remarks>The real and imaginary parts are the result of a cast to float.</remarks>
|
---|
| 1813 | public static explicit operator fcomplex(complex a) {
|
---|
| 1814 | return new fcomplex((float)a.real, (float)a.imag);
|
---|
| 1815 | }
|
---|
| 1816 | /// <summary>
|
---|
| 1817 | /// Cast value from complex number
|
---|
| 1818 | /// </summary>
|
---|
| 1819 | /// <param name="a">Complex value to cast</param>
|
---|
| 1820 | /// <returns>Number with the real part of a </returns>
|
---|
| 1821 | /// <remarks>The return value is the result of a cast to byte.</remarks>
|
---|
| 1822 | public static explicit operator byte(complex a) {
|
---|
| 1823 | return (byte) a.real;
|
---|
| 1824 | }
|
---|
| 1825 | /// <summary>
|
---|
| 1826 | /// Cast value from complex number
|
---|
| 1827 | /// </summary>
|
---|
| 1828 | /// <param name="a">Complex value to cast</param>
|
---|
| 1829 | /// <returns>Number with the real part of a </returns>
|
---|
| 1830 | /// <remarks>The return value is the result of a cast to Int32.</remarks>
|
---|
| 1831 | public static explicit operator Int32(complex a) {
|
---|
| 1832 | return (Int32) a.real;
|
---|
| 1833 | }
|
---|
| 1834 | /// <summary>
|
---|
| 1835 | /// Cast value from complex number
|
---|
| 1836 | /// </summary>
|
---|
| 1837 | /// <param name="a">Complex value to cast</param>
|
---|
| 1838 | /// <returns>number with the real part of a </returns>
|
---|
| 1839 | /// <remarks>the return value is the result of a cast to Int64.</remarks>
|
---|
| 1840 | public static explicit operator Int64(complex a) {
|
---|
| 1841 | return (Int64) a.real;
|
---|
| 1842 | }
|
---|
| 1843 |
|
---|
| 1844 | public static implicit operator complex(System.Numerics.Complex a) {
|
---|
| 1845 | return new complex(a.Real, a.Imaginary);
|
---|
| 1846 | }
|
---|
| 1847 | #endregion CAST_OPERATORS
|
---|
| 1848 |
|
---|
| 1849 | #region Functions Basic Math
|
---|
| 1850 | /// <summary>
|
---|
| 1851 | /// Absolute value of input
|
---|
| 1852 | /// </summary>
|
---|
| 1853 | /// <param name="input">Input value</param>
|
---|
| 1854 | /// <returns>The absolute value of the input</returns>
|
---|
| 1855 | public static double Abs(complex input) {
|
---|
| 1856 | return Math.Sqrt(input.real * input.real + input.imag * input.imag);
|
---|
| 1857 | }
|
---|
| 1858 | /// <summary>
|
---|
| 1859 | /// Phase angle of complex number
|
---|
| 1860 | /// </summary>
|
---|
| 1861 | /// <param name="input">Input value</param>
|
---|
| 1862 | /// <returns>The phase angle of the input</returns>
|
---|
| 1863 | /// <remarks>For the result the Atan2 function of the <see cref="Math"/> class is used.</remarks>
|
---|
| 1864 | public static double Angle(complex input) {
|
---|
| 1865 | return Math.Atan2(input.imag, input.real);
|
---|
| 1866 | }
|
---|
| 1867 | /// <summary>
|
---|
| 1868 | /// Arcus tangens of complex input
|
---|
| 1869 | /// </summary>
|
---|
| 1870 | /// <param name="input">Complex input</param>
|
---|
| 1871 | /// <returns>Arcus tangens of complex input</returns>
|
---|
| 1872 | /// <remarks></remarks>
|
---|
| 1873 | public static complex Atan(complex input) {
|
---|
| 1874 | complex ret = new complex(0, (float)0.5);
|
---|
| 1875 | return (ret * Log((complex.i + input) / (complex.i - input)));
|
---|
| 1876 | }
|
---|
| 1877 | /// <summary>
|
---|
| 1878 | /// Arcus cosinus of complex input
|
---|
| 1879 | /// </summary>
|
---|
| 1880 | /// <param name="input">Complex input</param>
|
---|
| 1881 | /// <returns>Arcus cosinus of input</returns>
|
---|
| 1882 | public static complex Acos(complex input) {
|
---|
| 1883 | complex ni = complex.i * -1.0;
|
---|
| 1884 | return complex.Log(complex.Sqrt(input * input - 1)
|
---|
| 1885 | + input) * ni;
|
---|
| 1886 | }
|
---|
| 1887 | /// <summary>
|
---|
| 1888 | /// Arcus cosinus of input
|
---|
| 1889 | /// </summary>
|
---|
| 1890 | /// <param name="input">Input value</param>
|
---|
| 1891 | /// <returns>Arcus cosinus of input</returns>
|
---|
| 1892 | public static complex Acos(double input) {
|
---|
| 1893 | if (Math.Abs(input) <= 1.0)
|
---|
| 1894 | return new complex(Math.Acos(input), 0.0);
|
---|
| 1895 | else {
|
---|
| 1896 | return Acos((complex)input);
|
---|
| 1897 | }
|
---|
| 1898 | }
|
---|
| 1899 | /// <summary>
|
---|
| 1900 | /// Arcus sinus of complex input
|
---|
| 1901 | /// </summary>
|
---|
| 1902 | /// <param name="input">Input value</param>
|
---|
| 1903 | /// <returns>Arcus sinus of input</returns>
|
---|
| 1904 | public static complex Asin(double input) {
|
---|
| 1905 | if (Math.Abs(input) <= 1.0)
|
---|
| 1906 | return new complex(Math.Asin(input), 0.0);
|
---|
| 1907 | else {
|
---|
| 1908 | return Asin((complex)input);
|
---|
| 1909 | }
|
---|
| 1910 | }
|
---|
| 1911 | /// <summary>
|
---|
| 1912 | /// Arcus sinus of input
|
---|
| 1913 | /// </summary>
|
---|
| 1914 | /// <param name="input">Input value</param>
|
---|
| 1915 | /// <returns>Arcus sinus of input</returns>
|
---|
| 1916 | public static complex Asin(complex input) {
|
---|
| 1917 | complex ret = Acos(input);
|
---|
| 1918 | ret.real = Math.PI / 2 - ret.real;
|
---|
| 1919 | return ret;
|
---|
| 1920 | }
|
---|
| 1921 | /// <summary>
|
---|
| 1922 | /// Round towards positive infinity
|
---|
| 1923 | /// </summary>
|
---|
| 1924 | /// <param name="input">Input value</param>
|
---|
| 1925 | /// <returns>Result is the next integer value greater then input</returns>
|
---|
| 1926 | /// <remarks>ILMath.Ceiling operates in both: real and imaginary parts seperately</remarks>
|
---|
| 1927 | public static complex Ceiling (complex input){
|
---|
| 1928 | return new complex(
|
---|
| 1929 | Math.Ceiling(input.real),
|
---|
| 1930 | Math.Ceiling(input.imag)
|
---|
| 1931 | );
|
---|
| 1932 | }
|
---|
| 1933 | /// <summary>
|
---|
| 1934 | /// Round towards negative infinity
|
---|
| 1935 | /// </summary>
|
---|
| 1936 | /// <param name="input">Input value</param>
|
---|
| 1937 | /// <returns>Result is the next integer value lower then input</returns>
|
---|
| 1938 | /// <remarks>ILMath.Floor operates in both: real and imaginary parts seperately</remarks>
|
---|
| 1939 | public static complex Floor (complex input){
|
---|
| 1940 | return new complex(
|
---|
| 1941 | Math.Floor(input.real),
|
---|
| 1942 | Math.Floor(input.imag)
|
---|
| 1943 | );
|
---|
| 1944 | }
|
---|
| 1945 | /// <summary>
|
---|
| 1946 | /// Rounds towards nearest integer
|
---|
| 1947 | /// </summary>
|
---|
| 1948 | /// <param name="input">Input value</param>
|
---|
| 1949 | /// <returns>Result is the nearest integer value for input</returns>
|
---|
| 1950 | /// <remarks>ILMath.Round operates in both: real and imaginary parts deperately</remarks>
|
---|
| 1951 | public static complex Round (complex input){
|
---|
| 1952 | return new complex(
|
---|
| 1953 | Math.Round(input.real),
|
---|
| 1954 | Math.Round(input.imag)
|
---|
| 1955 | );
|
---|
| 1956 | }
|
---|
| 1957 | /// <summary>
|
---|
| 1958 | /// Signum function
|
---|
| 1959 | /// </summary>
|
---|
| 1960 | /// <param name="input">Complex input </param>
|
---|
| 1961 | /// <returns>Sesult as input / Abs(input)</returns>
|
---|
| 1962 | /// <remarks>Sign(input) with input being complex returns the projection onto
|
---|
| 1963 | /// the unit circle. If input is 0+0i the result will be 0+0i.</remarks>
|
---|
| 1964 | public static complex Sign (complex input){
|
---|
| 1965 | if (input.real == 0.0 && input.imag == 0.0)
|
---|
| 1966 | return new complex();
|
---|
| 1967 | else {
|
---|
| 1968 | double mag = Math.Sqrt(input.real * input.real + input.imag * input.imag);
|
---|
| 1969 | return new complex(
|
---|
| 1970 | input.real / mag,
|
---|
| 1971 | input.imag / mag);
|
---|
| 1972 | }
|
---|
| 1973 | }
|
---|
| 1974 | /// <summary>
|
---|
| 1975 | /// Truncate a floating point complex value
|
---|
| 1976 | /// </summary>
|
---|
| 1977 | /// <param name="input">Input value</param>
|
---|
| 1978 | /// <returns>Integer part of input</returns>
|
---|
| 1979 | /// <remarks>Operates on real and imaginary parts seperately.</remarks>
|
---|
| 1980 | public static complex Truncate (complex input){
|
---|
| 1981 | return new complex(
|
---|
| 1982 | Math.Truncate(input.real),
|
---|
| 1983 | Math.Truncate(input.imag)
|
---|
| 1984 | );
|
---|
| 1985 | }
|
---|
| 1986 | /// <summary>
|
---|
| 1987 | /// Cosinus
|
---|
| 1988 | /// </summary>
|
---|
| 1989 | /// <param name="input">Input value</param>
|
---|
| 1990 | /// <returns>Cosine of input</returns>
|
---|
| 1991 | /// <remarks><para>The cosine is computed by the trigonometric euler equation: </para>
|
---|
| 1992 | /// <para>0.5 * [exp(i input) + exp(-i input)]</para></remarks>
|
---|
| 1993 | public static complex Cos(complex input) {
|
---|
| 1994 | complex i = new complex(0, 1.0);
|
---|
| 1995 | complex mi = new complex(0, -1.0);
|
---|
| 1996 | return (Exp(i * input) + Exp(mi * input)) / 2.0;
|
---|
| 1997 | }
|
---|
| 1998 | /// <summary>
|
---|
| 1999 | /// Cosinus hyperbolicus
|
---|
| 2000 | /// </summary>
|
---|
| 2001 | /// <param name="input">Input</param>
|
---|
| 2002 | /// <returns>Cosine hyperbolicus of input</returns>
|
---|
| 2003 | /// <remarks><para>The cosine is computed by the trigonometric euler equation: </para>
|
---|
| 2004 | /// <para>(Exp(input) + Exp(-1.0 * input)) / 2.0</para></remarks>
|
---|
| 2005 | public static complex Cosh(complex input) {
|
---|
| 2006 | return (Exp(input) + Exp(-1.0 * input)) / 2.0;
|
---|
| 2007 | }
|
---|
| 2008 | /// <summary>
|
---|
| 2009 | /// Sinus
|
---|
| 2010 | /// </summary>
|
---|
| 2011 | /// <param name="input">Input value</param>
|
---|
| 2012 | /// <returns>Sinus of input</returns>
|
---|
| 2013 | /// <remarks><para>The sinus is computed by the trigonometric euler equation: </para>
|
---|
| 2014 | /// <para>(Exp(i * input) - Exp(-1.0 * i * input)) / (2.0 * i)</para></remarks>
|
---|
| 2015 | public static complex Sin(complex input) {
|
---|
| 2016 | complex i = new complex(0, 1.0);
|
---|
| 2017 | complex mi = new complex(0, -1.0);
|
---|
| 2018 | return (Exp(i * input) - Exp(mi * input)) / (2.0 * i);
|
---|
| 2019 | }
|
---|
| 2020 | /// <summary>
|
---|
| 2021 | /// Sinus hyperbolicus
|
---|
| 2022 | /// </summary>
|
---|
| 2023 | /// <param name="input">Input</param>
|
---|
| 2024 | /// <returns>Sinus hyperbolicus of input</returns>
|
---|
| 2025 | /// <remarks><para>The sinus hyperbolicus is computed by the trigonometric euler equation: </para>
|
---|
| 2026 | /// <para>(Exp(input) - Exp(-1.0 * input)) / 2.0</para></remarks>
|
---|
| 2027 | public static complex Sinh(complex input) {
|
---|
| 2028 | return (Exp(input) - Exp(-1.0 * input)) / 2.0;
|
---|
| 2029 | }
|
---|
| 2030 | /// <summary>
|
---|
| 2031 | /// Complex exponent
|
---|
| 2032 | /// </summary>
|
---|
| 2033 | /// <param name="exponent">Exponent</param>
|
---|
| 2034 | /// <returns>Result of exp(exponent)</returns>
|
---|
| 2035 | /// <remarks>For complex exponents, exp(exponent) is computed by
|
---|
| 2036 | /// <para>complex.FromPol(Math.Exp(exponent.real), exponent.imag)</para></remarks>
|
---|
| 2037 | public static complex Exp(complex exponent) {
|
---|
| 2038 | return complex.FromPol(Math.Exp(exponent.real), exponent.imag);
|
---|
| 2039 | }
|
---|
| 2040 | /// <summary>
|
---|
| 2041 | /// Complex power for real exponent
|
---|
| 2042 | /// </summary>
|
---|
| 2043 | /// <param name="input">Basis</param>
|
---|
| 2044 | /// <param name="exponent">Exponent</param>
|
---|
| 2045 | /// <returns>Result of input power exponent</returns>
|
---|
| 2046 | /// <remarks>The computation will be carried out by
|
---|
| 2047 | /// <para>exp(log(input) * exponent)</para></remarks>
|
---|
| 2048 | public static complex Pow(complex input, double exponent) {
|
---|
| 2049 | complex ret = input.Log();
|
---|
| 2050 | ret.imag *= exponent;
|
---|
| 2051 | ret.real *= exponent;
|
---|
| 2052 | return ret.Exp();
|
---|
| 2053 | }
|
---|
| 2054 | /// <summary>
|
---|
| 2055 | /// Complex power - real basis, real exponent
|
---|
| 2056 | /// </summary>
|
---|
| 2057 | /// <param name="basis">Basis</param>
|
---|
| 2058 | /// <param name="exponent">Exponent</param>
|
---|
| 2059 | /// <returns>Complex number.</returns>
|
---|
| 2060 | /// <remarks>The result will be a complex number. For negative basis
|
---|
| 2061 | /// the basis will be converted to a complex number and the power
|
---|
| 2062 | /// will be computed in the complex plane.</remarks>
|
---|
| 2063 | public static complex Pow(double basis, double exponent) {
|
---|
| 2064 | if (basis >= 0.0)
|
---|
| 2065 | return Math.Pow(basis, exponent);
|
---|
| 2066 | else
|
---|
| 2067 | return Pow((complex)basis, exponent);
|
---|
| 2068 | }
|
---|
| 2069 | /// <summary>
|
---|
| 2070 | /// Complex power - complex exponent
|
---|
| 2071 | /// </summary>
|
---|
| 2072 | /// <param name="basis">Basis</param>
|
---|
| 2073 | /// <param name="exponent">Exponent</param>
|
---|
| 2074 | /// <returns>Complex number exp(log(basis) * exponent).</returns>
|
---|
| 2075 | /// <remarks>The result will be the complex number exp(log(basis) * exponent). </remarks>
|
---|
| 2076 | public static complex Pow(complex basis, complex exponent) {
|
---|
| 2077 | complex ret = (basis.Log() * exponent);
|
---|
| 2078 | return ret.Exp();
|
---|
| 2079 | }
|
---|
| 2080 | /// <summary>
|
---|
| 2081 | /// Square root
|
---|
| 2082 | /// </summary>
|
---|
| 2083 | /// <param name="input">Input value</param>
|
---|
| 2084 | /// <returns>The square root of input</returns>
|
---|
| 2085 | /// <remarks>If input is smaller than 0.0, the computation will be done in the complex plane. </remarks>
|
---|
| 2086 | public static complex Sqrt(double input) {
|
---|
| 2087 | if (input > 0.0)
|
---|
| 2088 | return new complex(Math.Sqrt(input), 0.0);
|
---|
| 2089 | else
|
---|
| 2090 | return Sqrt(input);
|
---|
| 2091 | }
|
---|
| 2092 | /// <summary>
|
---|
| 2093 | /// Square root
|
---|
| 2094 | /// </summary>
|
---|
| 2095 | /// <param name="input">Input value</param>
|
---|
| 2096 | /// <returns>The square root of input</returns>
|
---|
| 2097 | /// <remarks>Numerical recipes in C: Appendix C </remarks>
|
---|
| 2098 | public static complex Sqrt(complex input) {
|
---|
| 2099 | // Reference : numerical recipes in C: Appendix C
|
---|
| 2100 | complex ret = new complex();
|
---|
| 2101 | double x, y, w, r;
|
---|
| 2102 | if (input.real == 0.0 && input.imag == 0.0)
|
---|
| 2103 | return ret;
|
---|
| 2104 | else {
|
---|
| 2105 | x = (double)Math.Abs(input.real);
|
---|
| 2106 | y = (double)Math.Abs(input.imag);
|
---|
| 2107 | if (x >= y) {
|
---|
| 2108 | r = y / x;
|
---|
| 2109 | w = Math.Sqrt(x) * Math.Sqrt(0.5 * (1.0 + Math.Sqrt(1.0 + r * r)));
|
---|
| 2110 | } else {
|
---|
| 2111 | r = x / y;
|
---|
| 2112 | w = Math.Sqrt(y) * Math.Sqrt(0.5 * (r + Math.Sqrt(1.0 + r * r)));
|
---|
| 2113 | }
|
---|
| 2114 | if (input.real >= 0.0) {
|
---|
| 2115 | ret.real = w;
|
---|
| 2116 | ret.imag = input.imag / (2.0 * w);
|
---|
| 2117 | } else {
|
---|
| 2118 | ret.imag = (input.imag >= 0) ? w : -w;
|
---|
| 2119 | ret.real = input.imag / (2.0 * ret.imag);
|
---|
| 2120 | }
|
---|
| 2121 | return ret;
|
---|
| 2122 | }
|
---|
| 2123 | }
|
---|
| 2124 | /// <summary>
|
---|
| 2125 | /// Tangens
|
---|
| 2126 | /// </summary>
|
---|
| 2127 | /// <param name="input">Input value</param>
|
---|
| 2128 | /// <returns>Tangens of input</returns>
|
---|
| 2129 | /// <remarks>The tangens is
|
---|
| 2130 | /// <para>sin(input) / cos(input)</para>
|
---|
| 2131 | /// if cos(input) == 0.0+0.0i, INF will be returned.</remarks>
|
---|
| 2132 | public static complex Tan(complex input) {
|
---|
| 2133 | complex ci = Cos(input);
|
---|
| 2134 | if (ci.real == 0.0 && ci.imag == 0.0)
|
---|
| 2135 | return INF;
|
---|
| 2136 | return (Sin(input) / ci);
|
---|
| 2137 | }
|
---|
| 2138 | /// <summary>
|
---|
| 2139 | /// Tangens hyperbolicus
|
---|
| 2140 | /// </summary>
|
---|
| 2141 | /// <param name="input">Input value</param>
|
---|
| 2142 | /// <returns>Tangens hyperbolicus</returns>
|
---|
| 2143 | /// <remarks>The tangens hyperbolicus is
|
---|
| 2144 | /// <para>sinh(input) / cosh(input)</para>
|
---|
| 2145 | /// if cosh(input) == 0.0+0.0i, INF will be returned.</remarks>
|
---|
| 2146 | public static complex Tanh(complex input) {
|
---|
| 2147 | complex si = Cosh(input);
|
---|
| 2148 | if (si.real == 0.0 && si.imag == 0.0)
|
---|
| 2149 | return INF;
|
---|
| 2150 | return (Sinh(input) / si);
|
---|
| 2151 | }
|
---|
| 2152 | /// <summary>
|
---|
| 2153 | /// Complex logarithm
|
---|
| 2154 | /// </summary>
|
---|
| 2155 | /// <param name="input">Input value</param>
|
---|
| 2156 | /// <returns>Complex logarithm of input</returns>
|
---|
| 2157 | /// <remarks>The real part of the logarithm is computed by
|
---|
| 2158 | /// <para>log (abs (input))</para>
|
---|
| 2159 | /// <para>The imaginary part holds the phase of input.</para>
|
---|
| 2160 | /// </remarks>
|
---|
| 2161 | public static complex Log(complex input) {
|
---|
| 2162 | complex ret = new complex();
|
---|
| 2163 | ret.real = Math.Log(Math.Sqrt(input.real * input.real + input.imag * input.imag));
|
---|
| 2164 | ret.imag = Math.Atan2(input.imag, input.real);
|
---|
| 2165 | return ret;
|
---|
| 2166 | }
|
---|
| 2167 | /// <summary>
|
---|
| 2168 | /// Logarithm of real input
|
---|
| 2169 | /// </summary>
|
---|
| 2170 | /// <param name="input">Input value - may be negative</param>
|
---|
| 2171 | /// <returns>Complex logarithm</returns>
|
---|
| 2172 | public static complex Log(double input) {
|
---|
| 2173 | return Log (new complex(input,0.0));
|
---|
| 2174 | }
|
---|
| 2175 | /// <summary>
|
---|
| 2176 | /// Logarithm of base 10 of real input
|
---|
| 2177 | /// </summary>
|
---|
| 2178 | /// <param name="input">Input value - may be negative</param>
|
---|
| 2179 | /// <returns>Complex logarithm of base 10</returns>
|
---|
| 2180 | public static complex Log10(double input) {
|
---|
| 2181 | return Log(new complex(input,0.0)) * 0.43429448190325176;
|
---|
| 2182 | }
|
---|
| 2183 | /// <summary>
|
---|
| 2184 | /// Logarithm of base 2 of real input
|
---|
| 2185 | /// </summary>
|
---|
| 2186 | /// <param name="input">Input value - may be negative</param>
|
---|
| 2187 | /// <returns>Complex logarithm of base 2</returns>
|
---|
| 2188 | public static complex Log2(double input) {
|
---|
| 2189 | return Log(new complex(input,0.0)) * 1.4426950408889641;
|
---|
| 2190 | }
|
---|
| 2191 | /// <summary>
|
---|
| 2192 | /// Logarithm of base 10
|
---|
| 2193 | /// </summary>
|
---|
| 2194 | /// <param name="input">Input value</param>
|
---|
| 2195 | /// <returns>Logarithm of base 10</returns>
|
---|
| 2196 | /// <seealso cref="ILNumerics.complex.Log(complex)"/>
|
---|
| 2197 | public static complex Log10(complex input) {
|
---|
| 2198 | return Log(input) * 0.43429448190325176;
|
---|
| 2199 | }
|
---|
| 2200 | /// <summary>
|
---|
| 2201 | /// Logarithm of base 2
|
---|
| 2202 | /// </summary>
|
---|
| 2203 | /// <param name="input">Input value</param>
|
---|
| 2204 | /// <returns>Logarithm of base 2.</returns>
|
---|
| 2205 | /// <seealso cref="ILNumerics.complex.Log(complex)"/>
|
---|
| 2206 | public static complex Log2(complex input) {
|
---|
| 2207 | return Log(input) * 1.4426950408889634;
|
---|
| 2208 | }
|
---|
| 2209 | /// <summary>
|
---|
| 2210 | /// Convert polar notation into cartesian notation
|
---|
| 2211 | /// </summary>
|
---|
| 2212 | /// <param name="magnitude">Magnitude</param>
|
---|
| 2213 | /// <param name="angle">Phase</param>
|
---|
| 2214 | /// <returns>Complex value having magnitude and phase</returns>
|
---|
| 2215 | public static complex FromPol(double magnitude, double angle) {
|
---|
| 2216 | return new complex(
|
---|
| 2217 | magnitude * Math.Cos(angle),
|
---|
| 2218 | magnitude * Math.Sin(angle)
|
---|
| 2219 | );
|
---|
| 2220 | }
|
---|
| 2221 | /// <summary>
|
---|
| 2222 | /// Convert to string
|
---|
| 2223 | /// </summary>
|
---|
| 2224 | /// <returns>String displaying the comlex number (full precision)</returns>
|
---|
| 2225 | public override String ToString() {
|
---|
| 2226 | if (imag>=0)
|
---|
| 2227 | return String.Format("{0} + {1}i",real,imag);
|
---|
| 2228 | else
|
---|
| 2229 | return String.Format("{0} - {1}i",real,-imag);
|
---|
| 2230 | }
|
---|
| 2231 | private static string m_precSpecI = "";
|
---|
| 2232 | private static string m_precSpecR = "";
|
---|
| 2233 | private static int m_lastDigits = 0;
|
---|
| 2234 | /// <summary>
|
---|
| 2235 | /// Print formated output of this number, determine number of digits
|
---|
| 2236 | /// </summary>
|
---|
| 2237 | /// <param name="digits">Number of digits</param>
|
---|
| 2238 | /// <returns>Formated output</returns>
|
---|
| 2239 | public string ToString(int digits) {
|
---|
| 2240 | if (digits < 1) return "";
|
---|
| 2241 | if (digits != m_lastDigits) {
|
---|
| 2242 | m_lastDigits = digits;
|
---|
| 2243 | m_precSpecR = String.Format("{{0:f{0}}}",digits);
|
---|
| 2244 | m_precSpecI = String.Format("{{1:f{0}}}i",digits);
|
---|
| 2245 | }
|
---|
| 2246 | if (imag >= 0) {
|
---|
| 2247 | return String.Format(m_precSpecR+"+"+m_precSpecI,real,imag);
|
---|
| 2248 | } else {
|
---|
| 2249 | return String.Format(m_precSpecR+"-"+m_precSpecI,real,-imag);
|
---|
| 2250 | }
|
---|
| 2251 | }
|
---|
| 2252 | /// <summary>
|
---|
| 2253 | /// Magnitude of this complex instance
|
---|
| 2254 | /// </summary>
|
---|
| 2255 | /// <returns>Magnitude</returns>
|
---|
| 2256 | public double Abs() {
|
---|
| 2257 | return Math.Sqrt(real * real + imag * imag);
|
---|
| 2258 | }
|
---|
| 2259 | /// <summary>
|
---|
| 2260 | /// Phase of this complex instance
|
---|
| 2261 | /// </summary>
|
---|
| 2262 | /// <returns>Phase</returns>
|
---|
| 2263 | public double Angle() {
|
---|
| 2264 | return Math.Atan2(imag, real);
|
---|
| 2265 | }
|
---|
| 2266 | /// <summary>
|
---|
| 2267 | /// Arcus cosinus of this complex instance
|
---|
| 2268 | /// </summary>
|
---|
| 2269 | /// <returns>Arcus cosinus</returns>
|
---|
| 2270 | public complex Acos() {
|
---|
| 2271 | complex ret = new complex(0, -1);
|
---|
| 2272 | return complex.Log(complex.Sqrt(this * this - 1)
|
---|
| 2273 | + this) * ret;
|
---|
| 2274 | }
|
---|
| 2275 | /// <summary>
|
---|
| 2276 | /// Arcus sinus of this complex instance
|
---|
| 2277 | /// </summary>
|
---|
| 2278 | /// <returns>arcus sinus</returns>
|
---|
| 2279 | public complex Asin() {
|
---|
| 2280 | complex ret = Acos(this);
|
---|
| 2281 | ret.real = Math.PI / 2 - ret.real;
|
---|
| 2282 | return ret;
|
---|
| 2283 | }
|
---|
| 2284 | /// <summary>
|
---|
| 2285 | /// Exponential / power of base e
|
---|
| 2286 | /// </summary>
|
---|
| 2287 | /// <returns>Power of base e</returns>
|
---|
| 2288 | public complex Exp() {
|
---|
| 2289 | return complex.FromPol(Math.Exp(real), imag);
|
---|
| 2290 | }
|
---|
| 2291 | /// <summary>
|
---|
| 2292 | /// Complex power real exponent
|
---|
| 2293 | /// </summary>
|
---|
| 2294 | /// <param name="exponent">Exponent</param>
|
---|
| 2295 | /// <returns>New complex number with result</returns>
|
---|
| 2296 | /// <remarks>If this instance is a and the exponent is e than
|
---|
| 2297 | /// the result will be the complex number exp(log(a) * e). </remarks>
|
---|
| 2298 | public complex Pow(double exponent) {
|
---|
| 2299 | complex ret = Log();
|
---|
| 2300 | ret.imag *= exponent;
|
---|
| 2301 | ret.real *= exponent;
|
---|
| 2302 | return ret.Exp();
|
---|
| 2303 | }
|
---|
| 2304 | /// <summary>
|
---|
| 2305 | /// Complex power - complex exponent
|
---|
| 2306 | /// </summary>
|
---|
| 2307 | /// <param name="exponent">Exponent</param>
|
---|
| 2308 | /// <returns>Complex number exp(log(this) * exponent).</returns>
|
---|
| 2309 | /// <remarks>If this instance is a than
|
---|
| 2310 | /// the result will be the complex number exp(log(a) * exponent). </remarks>
|
---|
| 2311 | public complex Pow(complex exponent) {
|
---|
| 2312 | complex ret = (Log() * exponent);
|
---|
| 2313 | return ret.Exp();
|
---|
| 2314 | }
|
---|
| 2315 | /// <summary>
|
---|
| 2316 | /// Square root of this complex value
|
---|
| 2317 | /// </summary>
|
---|
| 2318 | /// <returns>Square root of this complex value</returns>
|
---|
| 2319 | public complex Sqrt() {
|
---|
| 2320 | // Reference : numerical recipes in C: Appendix C
|
---|
| 2321 | complex ret = new complex();
|
---|
| 2322 | double x, y, w, r;
|
---|
| 2323 | if (real == 0.0 && imag == 0.0)
|
---|
| 2324 | return ret;
|
---|
| 2325 | else {
|
---|
| 2326 | x = (double)Math.Abs(real);
|
---|
| 2327 | y = (double)Math.Abs(imag);
|
---|
| 2328 | if (x >= y) {
|
---|
| 2329 | r = y / x;
|
---|
| 2330 | w = Math.Sqrt(x) * Math.Sqrt(0.5 * (1.0 + Math.Sqrt(1.0 + r * r)));
|
---|
| 2331 | } else {
|
---|
| 2332 | r = x / y;
|
---|
| 2333 | w = Math.Sqrt(y) * Math.Sqrt(0.5 * (r + Math.Sqrt(1.0 + r * r)));
|
---|
| 2334 | }
|
---|
| 2335 | if (real >= 0.0) {
|
---|
| 2336 | ret.real = w;
|
---|
| 2337 | ret.imag = imag / (2.0 * w);
|
---|
| 2338 | } else {
|
---|
| 2339 | ret.imag = (imag >= 0) ? w : -w;
|
---|
| 2340 | ret.real = imag / ( 2.0 * ret.imag );
|
---|
| 2341 | }
|
---|
| 2342 | return ret;
|
---|
| 2343 | }
|
---|
| 2344 | }
|
---|
| 2345 | /// <summary>
|
---|
| 2346 | /// Logarithm of base e
|
---|
| 2347 | /// </summary>
|
---|
| 2348 | /// <returns>Logarithm of base e</returns>
|
---|
| 2349 | /// <remarks>The logarithm of a complex number A is defined as follows: <br />
|
---|
| 2350 | /// <list type="none"><item>real part: log(abs(A))</item>
|
---|
| 2351 | /// <item>imag part: Atan2(imag(A),real(A))</item></list>
|
---|
| 2352 | /// </remarks>
|
---|
| 2353 | public complex Log() {
|
---|
| 2354 | complex ret = new complex();
|
---|
| 2355 | ret.real = Math.Log(Math.Sqrt(real * real + imag * imag));
|
---|
| 2356 | ret.imag = Math.Atan2(imag, real);
|
---|
| 2357 | return ret;
|
---|
| 2358 | }
|
---|
| 2359 | /// <summary>
|
---|
| 2360 | /// Test if any of real or imaginary parts are NAN's
|
---|
| 2361 | /// </summary>
|
---|
| 2362 | /// <param name="input">Complex number to test</param>
|
---|
| 2363 | /// <returns>true if any of real or imag part is not a number</returns>
|
---|
| 2364 | public static bool IsNaN(complex input) {
|
---|
| 2365 | if (double.IsNaN(input.real) || double.IsNaN(input.imag))
|
---|
| 2366 | return true;
|
---|
| 2367 | else
|
---|
| 2368 | return false;
|
---|
| 2369 | }
|
---|
| 2370 | /// <summary>
|
---|
| 2371 | /// Test if any of real or imaginary parts are infinite
|
---|
| 2372 | /// </summary>
|
---|
| 2373 | /// <param name="input">Complex number to test</param>
|
---|
| 2374 | /// <returns>true if any of real or imag part is infinite</returns>
|
---|
| 2375 | public static bool IsInfinity(complex input) {
|
---|
| 2376 | if (double.IsInfinity(input.real) || double.IsInfinity(input.imag))
|
---|
| 2377 | return true;
|
---|
| 2378 | else
|
---|
| 2379 | return false;
|
---|
| 2380 | }
|
---|
| 2381 | /// <summary>
|
---|
| 2382 | /// Test if any of real or imaginary parts are pos.nfinite
|
---|
| 2383 | /// </summary>
|
---|
| 2384 | /// <param name="input">Complex number to test</param>
|
---|
| 2385 | /// <returns>true if any of real or imag part is positive infinite</returns>
|
---|
| 2386 | public static bool IsPositiveInfinity(complex input) {
|
---|
| 2387 | if (double.IsPositiveInfinity(input.real) || double.IsPositiveInfinity(input.imag))
|
---|
| 2388 | return true;
|
---|
| 2389 | else
|
---|
| 2390 | return false;
|
---|
| 2391 | }
|
---|
| 2392 | /// <summary>
|
---|
| 2393 | /// Test if any of real or imaginary parts are neg. infinite
|
---|
| 2394 | /// </summary>
|
---|
| 2395 | /// <param name="input">Complex number to test</param>
|
---|
| 2396 | /// <returns>true if any of real or imag part is negative infinite</returns>
|
---|
| 2397 | public static bool IsNegativeInfinity(complex input) {
|
---|
| 2398 | if (double.IsNegativeInfinity(input.real) || double.IsNegativeInfinity(input.imag))
|
---|
| 2399 | return true;
|
---|
| 2400 | else
|
---|
| 2401 | return false;
|
---|
| 2402 | }
|
---|
| 2403 | /// <summary>
|
---|
| 2404 | /// Test if any of real or imaginary parts are finite
|
---|
| 2405 | /// </summary>
|
---|
| 2406 | /// <param name="input">Complex number to test</param>
|
---|
| 2407 | /// <returns>true if any of real and imag part is finite</returns>
|
---|
| 2408 | public static bool IsFinite (complex input) {
|
---|
| 2409 | if (ILMath.isfinite(input.real) && ILMath.isfinite(input.imag))
|
---|
| 2410 | return true;
|
---|
| 2411 | else
|
---|
| 2412 | return false;
|
---|
| 2413 | }
|
---|
| 2414 | /// <summary>
|
---|
| 2415 | /// Test if both of real or imaginary parts are 0
|
---|
| 2416 | /// </summary>
|
---|
| 2417 | /// <returns>true if real and imag part is 0</returns>
|
---|
| 2418 | public bool iszero() {
|
---|
| 2419 | if (real == 0.0 && imag == 0.0)
|
---|
| 2420 | return true;
|
---|
| 2421 | else
|
---|
| 2422 | return false;
|
---|
| 2423 | }
|
---|
| 2424 | #endregion Functions Basic Math
|
---|
| 2425 | }
|
---|
| 2426 |
|
---|
| 2427 | }
|
---|