├── .github ├── FUNDING.yml └── workflows │ ├── arduino-lint.yml │ ├── arduino_test_runner.yml │ └── jsoncheck.yml ├── library.properties ├── library.json ├── .arduino-ci.yml ├── examples ├── const │ └── const.ino ├── performance │ ├── preformanceOutput_0.2.0.txt │ ├── preformanceOutput_0.3.1.txt │ └── performance.ino ├── array │ └── array.ino └── complex │ ├── referenceOutput_0.2.0.txt │ ├── referenceOutput_0.3.1.txt │ └── complex.ino ├── keywords.txt ├── LICENSE ├── CHANGELOG.md ├── Complex.h ├── README.md ├── test └── unit_test_001.cpp └── Complex.cpp /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: RobTillaart 4 | custom: "https://www.paypal.me/robtillaart" 5 | -------------------------------------------------------------------------------- /.github/workflows/arduino-lint.yml: -------------------------------------------------------------------------------- 1 | name: Arduino-lint 2 | 3 | on: [push, pull_request] 4 | jobs: 5 | lint: 6 | runs-on: ubuntu-latest 7 | timeout-minutes: 5 8 | steps: 9 | - uses: actions/checkout@v5 10 | - uses: arduino/arduino-lint-action@v2 11 | with: 12 | library-manager: update 13 | compliance: strict -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Complex 2 | version=0.3.5 3 | author=Rob Tillaart 4 | maintainer=Rob Tillaart 5 | sentence=Arduino library for Complex math. 6 | paragraph=implements Printable interface 7 | category=Data Processing 8 | url=https://github.com/RobTillaart/Complex 9 | architectures=* 10 | includes=Complex.h 11 | depends= 12 | -------------------------------------------------------------------------------- /.github/workflows/arduino_test_runner.yml: -------------------------------------------------------------------------------- 1 | name: Arduino CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | runTest: 7 | runs-on: ubuntu-latest 8 | timeout-minutes: 20 9 | 10 | steps: 11 | - uses: actions/checkout@v5 12 | - uses: ruby/setup-ruby@v1 13 | with: 14 | ruby-version: 2.6 15 | - run: | 16 | gem install arduino_ci 17 | arduino_ci.rb 18 | -------------------------------------------------------------------------------- /.github/workflows/jsoncheck.yml: -------------------------------------------------------------------------------- 1 | name: JSON check 2 | 3 | on: 4 | push: 5 | paths: 6 | - '**.json' 7 | pull_request: 8 | paths: 9 | - '**.json' 10 | 11 | jobs: 12 | test: 13 | runs-on: ubuntu-latest 14 | timeout-minutes: 5 15 | steps: 16 | - uses: actions/checkout@v5 17 | - name: json-syntax-check 18 | uses: limitusus/json-syntax-check@v2 19 | with: 20 | pattern: "\\.json$" -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Complex", 3 | "keywords": "Complex,numbers,Imaginary,phase,modulus,polar,conjugate,math,sin,cos,tan,exp,pow", 4 | "description": "Library for Complex math. Implements Printable interface.", 5 | "authors": 6 | [ 7 | { 8 | "name": "Rob Tillaart", 9 | "email": "Rob.Tillaart@gmail.com", 10 | "maintainer": true 11 | } 12 | ], 13 | "repository": 14 | { 15 | "type": "git", 16 | "url": "https://github.com/RobTillaart/Complex.git" 17 | }, 18 | "version": "0.3.5", 19 | "license": "MIT", 20 | "frameworks": "*", 21 | "platforms": "*", 22 | "headers": "Complex.h" 23 | } 24 | -------------------------------------------------------------------------------- /.arduino-ci.yml: -------------------------------------------------------------------------------- 1 | platforms: 2 | rpipico: 3 | board: rp2040:rp2040:rpipico 4 | package: rp2040:rp2040 5 | gcc: 6 | features: 7 | defines: 8 | - ARDUINO_ARCH_RP2040 9 | warnings: 10 | flags: 11 | 12 | packages: 13 | rp2040:rp2040: 14 | url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json 15 | 16 | compile: 17 | # Choosing to run compilation tests on 2 different Arduino platforms 18 | platforms: 19 | - uno 20 | # - due 21 | # - zero 22 | # - leonardo 23 | - m4 24 | - esp32 25 | # - esp8266 26 | # - mega2560 27 | - rpipico 28 | 29 | -------------------------------------------------------------------------------- /examples/const/const.ino: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: const.ino 3 | // AUTHOR: Rob Tillaart 4 | // DATE: 2021-11-15 5 | // PURPOSE: test complex math - https://github.com/RobTillaart/Complex/issues/7 6 | // URL: https://github.com/RobTillaart/Complex 7 | 8 | 9 | #include "Complex.h" 10 | 11 | 12 | void setup() 13 | { 14 | Serial.begin(115200); 15 | Serial.println(); 16 | Serial.println(__FILE__); 17 | Serial.print("COMPLEX_LIB_VERSION: "); 18 | Serial.println(COMPLEX_LIB_VERSION); 19 | Serial.println(); 20 | 21 | const Complex unity(1, 0); 22 | Complex a(1,1); 23 | Complex b(2,2); 24 | Complex c = unity * a + b; 25 | 26 | Serial.println(a); 27 | Serial.println(b); 28 | Serial.println(c); 29 | 30 | const Complex d(1,1); 31 | // The next line is a warning on AVR 32 | // But an error on other platforms (which is correct) 33 | // d *= b; 34 | Serial.println(d); 35 | 36 | Serial.println("\ndone..."); 37 | } 38 | 39 | 40 | void loop() 41 | { 42 | } 43 | 44 | 45 | // -- END OF FILE -- 46 | 47 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | # Syntax Colouring Map For Complex 2 | 3 | # Data types (KEYWORD1) 4 | Complex KEYWORD1 5 | 6 | 7 | # Methods and Functions (KEYWORD2) 8 | set KEYWORD2 9 | setReal KEYWORD2 10 | setImag KEYWORD2 11 | real KEYWORD2 12 | imag KEYWORD2 13 | polar KEYWORD2 14 | phase KEYWORD2 15 | modulus KEYWORD2 16 | conjugate KEYWORD2 17 | reciprocal KEYWORD2 18 | 19 | c_sqrt KEYWORD2 20 | c_sqr KEYWORD2 21 | c_exp KEYWORD2 22 | c_log KEYWORD2 23 | c_log10 KEYWORD2 24 | c_pow KEYWORD2 25 | c_logn KEYWORD2 26 | 27 | c_sin KEYWORD2 28 | c_cos KEYWORD2 29 | c_tan KEYWORD2 30 | c_asin KEYWORD2 31 | c_acos KEYWORD2 32 | c_atan KEYWORD2 33 | 34 | c_csc KEYWORD2 35 | c_sec KEYWORD2 36 | c_cot KEYWORD2 37 | c_acsc KEYWORD2 38 | c_asec KEYWORD2 39 | c_acot KEYWORD2 40 | 41 | c_sinh KEYWORD2 42 | c_cosh KEYWORD2 43 | c_tanh KEYWORD2 44 | c_asinh KEYWORD2 45 | c_acosh KEYWORD2 46 | c_atanh KEYWORD2 47 | 48 | c_csch KEYWORD2 49 | c_sech KEYWORD2 50 | c_coth KEYWORD2 51 | c_acsch KEYWORD2 52 | c_asech KEYWORD2 53 | c_acoth KEYWORD2 54 | 55 | 56 | # Constants (LITERAL1) 57 | COMPLEX_LIB_VERSION LITERAL1 58 | 59 | 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-2025 Rob Tillaart 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/performance/preformanceOutput_0.2.0.txt: -------------------------------------------------------------------------------- 1 | Complex numbers performance test for Arduino: 0.2.0 2 | 3 | 5 constructors 12 4 | set(0,0) 4 5 | c1 + 1 2024 6 | c1 + c2 2036 7 | += c2 1616 8 | c5 = -c1 692 9 | c1 - 3 1440 10 | c1 - c2 2112 11 | c5 -= c2 1552 12 | c1 * 3 5728 13 | c1 * c2 5592 14 | c5 *= c2 4408 15 | c1 / 3 12356 16 | c1 / c2 12232 17 | c5 /= c2 6336 18 | 19 | real() 4 20 | imag() 4 21 | modulus() 6000 22 | phase 204 23 | polar() 260 24 | conjugate() 676 25 | reciprocal(); 8160 26 | 27 | c_sqr() 4672 28 | c_exp() 42588 29 | c_log() 39628 30 | c_pow(2) 88384 31 | c_sqrt() 8520 32 | c_logn(c4) 72644 33 | c_pow(c5) 61896 34 | c_log10() 40776 35 | 36 | c_sin() 57968 37 | c_asin() 75552 38 | c_cos() 58076 39 | c_acos() 73968 40 | c_tan() 129156 41 | c_atan() 66864 42 | 43 | c_csc() 70372 44 | c_acsc() 85828 45 | c_sec() 70412 46 | c_asec() 87528 47 | c_cot() 141652 48 | c_acot() 74420 49 | 50 | c_sinh() 57964 51 | c_asinh() 64612 52 | c_cosh() 58060 53 | c_acosh() 62200 54 | c_tanh() 129148 55 | c_atanh() 91388 56 | 57 | c_csch() 70452 58 | c_acsch() 66464 59 | c_sech() 70420 60 | c_asech() 77548 61 | c_coth() 141584 62 | c_acoth() 98544 63 | 64 | 2337184 65 | 66 | .. Complex done 67 | -------------------------------------------------------------------------------- /examples/performance/preformanceOutput_0.3.1.txt: -------------------------------------------------------------------------------- 1 | 2 | Complex numbers performance test for Arduino: 0.3.1 3 | 4 | 5 constructors 16 5 | set(0,0) 4 6 | c1 + 1 2020 7 | c1 + c2 2032 8 | += c2 1616 9 | c5 = -c1 692 10 | c1 - 3 1444 11 | c1 - c2 2112 12 | c5 -= c2 1548 13 | c1 * 3 5724 14 | c1 * c2 5592 15 | c5 *= c2 4408 16 | c1 / 3 12356 17 | c1 / c2 12228 18 | c5 /= c2 6336 19 | 20 | real() 4 21 | imag() 4 22 | modulus() 6000 23 | phase 204 24 | polar() 256 25 | conjugate() 680 26 | reciprocal(); 8156 27 | 28 | c_sqr() 4672 29 | c_exp() 42584 30 | c_log() 39636 31 | c_pow(2) 88380 32 | c_sqrt() 8504 33 | c_logn(c4) 72644 34 | c_pow(c5) 61896 35 | c_log10() 40780 36 | 37 | c_sin() 57972 38 | c_asin() 75556 39 | c_cos() 58060 40 | c_acos() 73968 41 | c_tan() 129156 42 | c_atan() 66864 43 | 44 | c_csc() 70372 45 | c_acsc() 85824 46 | c_sec() 70416 47 | c_asec() 87528 48 | c_cot() 141652 49 | c_acot() 74420 50 | 51 | c_sinh() 57964 52 | c_asinh() 64616 53 | c_cosh() 58060 54 | c_acosh() 62204 55 | c_tanh() 129148 56 | c_atanh() 91384 57 | 58 | c_csch() 70448 59 | c_acsch() 66464 60 | c_sech() 70420 61 | c_asech() 77548 62 | c_coth() 141584 63 | c_acoth() 98540 64 | 65 | 2337140 66 | 67 | .. Complex done 68 | -------------------------------------------------------------------------------- /examples/array/array.ino: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: array.ino 3 | // AUTHOR: Rob Tillaart 4 | // PURPOSE: example complex array 5 | // URL: https://github.com/RobTillaart/Complex 6 | 7 | 8 | #include "Complex.h" 9 | 10 | Complex samples[100]; 11 | 12 | 13 | void setup() 14 | { 15 | Serial.begin(115200); 16 | Serial.println(); 17 | Serial.println(__FILE__); 18 | Serial.print("COMPLEX_LIB_VERSION: "); 19 | Serial.println(COMPLEX_LIB_VERSION); 20 | Serial.println(); 21 | 22 | Serial.println("\n1. Read into array"); 23 | for (int i = 0; i < 100; i++) 24 | { 25 | float re = analogRead(A0) / 1023.0; 26 | float im = analogRead(A1) / 1023.0; 27 | samples[i].set(re, im); 28 | } 29 | 30 | Serial.println("\n2. Print array"); 31 | for (int i = 0; i < 100; i++) 32 | { 33 | if (i % 5 == 0) Serial.println(); 34 | Serial.print(samples[i]); 35 | Serial.print("\t"); 36 | } 37 | Serial.println(); 38 | 39 | Serial.println("\n3. Sum array"); 40 | Complex sum; 41 | for (int i = 0; i < 100; i++) 42 | { 43 | sum += samples[i]; 44 | } 45 | Serial.println(sum); 46 | 47 | Serial.println("\n done"); 48 | } 49 | 50 | 51 | void loop() 52 | { 53 | } 54 | 55 | 56 | 57 | // -- END OF FILE -- 58 | 59 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log Complex 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/). 7 | 8 | 9 | ## [0.3.5] - 2025-10-15 10 | - update GitHub actions 11 | - update examples 12 | - minor edits 13 | 14 | ## [0.3.4] - 2024-01-02 15 | - fix examples 16 | - update readme.md 17 | - minor edits 18 | 19 | ## [0.3.3] - 2023-10-18 20 | - update readme.md 21 | 22 | ## [0.3.2] - 2022-10-29 23 | - add changelog.md 24 | - add rp2040 to build-CI 25 | - minor edit unit test 26 | 27 | ## [0.3.1] - 2021-12-14 28 | - update library.json 29 | - update license 30 | - minor edits 31 | 32 | ## [0.3.0] - 2021-11-15 33 | - fix #7 adding const to operators 34 | 35 | ---- 36 | 37 | ## [0.2.4] - 2021-10-19 38 | - update build-CI. 39 | 40 | ## [0.2.3] - 2021-09-14 41 | - fix build-CI 42 | - update readme.md 43 | 44 | ## [0.2.2] - 2020-12-16 45 | - add arduino-ci + unit test (starter) 46 | - setReal(), setImag() 47 | 48 | ## [0.2.1] - 2020-06-05 49 | - fix library.json 50 | 51 | ## [0.2.0] - 2020-03-29 52 | - #pragma once, 53 | - create own repo 54 | 55 | ---- 56 | 57 | ## [0.1.12] - 2018-04-02 58 | - fix issue #33 double -> float 59 | 60 | ## [0.1.11] - 2018-01-29 61 | - fix sin and cos formula - issue #91 62 | 63 | ## [0.1.10] - 2018-01-15 64 | - uppercase #define COMPLEX_H 65 | 66 | ## [0.1.09] - 2016-10-15 67 | - added (0,0) constructor 68 | 69 | ## [0.1.08] - 2015-06-03 70 | - refactor 71 | 72 | ## [0.1.07] - 2015-06-03 73 | - refactor interfaces 74 | 75 | some missing history 76 | 77 | ## [0.1.0] - 2013-09-23 78 | - initial version. 79 | 80 | -------------------------------------------------------------------------------- /examples/complex/referenceOutput_0.2.0.txt: -------------------------------------------------------------------------------- 1 | Complex numbers test for Arduino: 0.2.0 2 | 3 | 1. Print Complex, set, real, imag 4 | 1.000 0.000i 5 | 10.000 -2.000i 6 | 3.000 0.000i 7 | -10.000 4.000i 8 | -5.000 -5.000i 9 | 0.000 0.000i 10 | 0.00 11 | 0.00 12 | 13 | 2. == != 14 | ok :) 15 | ok :) 16 | ok :) 17 | 18 | 3. negation - 19 | -10.000 2.000i 20 | 10.000 -2.000i 21 | ok :) 22 | 23 | 4. + - 24 | 13.000 -2.000i 25 | 13.000 -2.000i 26 | 7.000 -2.000i 27 | 7.000 -2.000i 28 | 29 | 5. * / 30 | 30.000 -6.000i 31 | 90.000 -18.000i 32 | 30.000 -6.000i 33 | 10.000 -2.000i 34 | 10.000 -2.000i 35 | 10.000 -2.000i 36 | 37 | 6. assign += -= *= /= 38 | 20.000 -4.000i 39 | 23.000 -4.000i 40 | 13.000 -2.000i 41 | 10.000 -2.000i 42 | 96.000 -40.000i 43 | 288.000 -120.000i 44 | 30.000 -6.000i 45 | 10.000 -2.000i 46 | 47 | 7. phase modulus polar 48 | 10.000 -2.000i 49 | 10.20 50 | -0.20 51 | 10.000 -2.000i 52 | 53 | 8. conjugate reciprocal 54 | 10.000 2.000i 55 | 10.000 -2.000i 56 | 0.096 0.019i 57 | 10.000 -2.000i 58 | 59 | 9. power: exp log pow sqrt sqr logn log10 60 | 96.000 -40.000i 61 | -9166.239 -20028.597i 62 | 10.000 -2.000i 63 | 96.000 -40.000i 64 | 10.000 -2.000i 65 | 96.000 -40.000i 66 | 880.000 -592.000i 67 | 10.000 -2.000i 68 | 0.534 0.542i 69 | 10.000 -2.000i 70 | 1.009 -0.086i 71 | 72 | 10. gonio: sin cos tan asin acos atan 73 | 0.541 0.457i 74 | 0.500 0.500i 75 | 0.990 -0.250i 76 | 0.500 0.500i 77 | 0.404 0.564i 78 | 0.500 0.500i 79 | 80 | 11. gonio csc sec cot acsc asec acot 81 | 1.078 -0.912i 82 | 0.500 0.500i 83 | 0.950 0.240i 84 | 0.500 0.500i 85 | 0.839 -1.172i 86 | 0.500 0.500i 87 | 88 | 12. gonio hyperbolicus I 89 | 0.457 0.541i 90 | 0.500 0.500i 91 | 0.990 0.250i 92 | 0.500 0.500i 93 | 0.564 0.404i 94 | 0.500 0.500i 95 | 96 | 13. gonio hyperbolicus II 97 | 0.912 -1.078i 98 | 0.500 0.500i 99 | 0.950 -0.240i 100 | 0.500 0.500i 101 | 1.172 -0.839i 102 | 0.500 0.500i 103 | 104 | 14. gonio bug fix (minimal) test 105 | 3.000 4.000i 106 | 1.000 0.000i 107 | 108 | .. Complex done 109 | 521964 110 | 1.000 0.000i 111 | -------------------------------------------------------------------------------- /examples/complex/referenceOutput_0.3.1.txt: -------------------------------------------------------------------------------- 1 | Complex numbers test for Arduino: 0.3.1 2 | 3 | 1. Print Complex, set, real, imag 4 | 1.000 0.000i 5 | 10.000 -2.000i 6 | 3.000 0.000i 7 | -10.000 4.000i 8 | -5.000 -5.000i 9 | 0.000 0.000i 10 | 0.00 11 | 0.00 12 | 13 | 2. == != 14 | ok :) 15 | ok :) 16 | ok :) 17 | 18 | 3. negation - 19 | -10.000 2.000i 20 | 10.000 -2.000i 21 | ok :) 22 | 23 | 4. + - 24 | 13.000 -2.000i 25 | 13.000 -2.000i 26 | 7.000 -2.000i 27 | 7.000 -2.000i 28 | 29 | 5. * / 30 | 30.000 -6.000i 31 | 90.000 -18.000i 32 | 30.000 -6.000i 33 | 10.000 -2.000i 34 | 10.000 -2.000i 35 | 10.000 -2.000i 36 | 37 | 6. assign += -= *= /= 38 | 20.000 -4.000i 39 | 23.000 -4.000i 40 | 13.000 -2.000i 41 | 10.000 -2.000i 42 | 96.000 -40.000i 43 | 288.000 -120.000i 44 | 30.000 -6.000i 45 | 10.000 -2.000i 46 | 47 | 7. phase modulus polar 48 | 10.000 -2.000i 49 | 10.20 50 | -0.20 51 | 10.000 -2.000i 52 | 53 | 8. conjugate reciprocal 54 | 10.000 2.000i 55 | 10.000 -2.000i 56 | 0.096 0.019i 57 | 10.000 -2.000i 58 | 59 | 9. power: exp log pow sqrt sqr logn log10 60 | 96.000 -40.000i 61 | -9166.239 -20028.597i 62 | 10.000 -2.000i 63 | 96.000 -40.000i 64 | 10.000 -2.000i 65 | 96.000 -40.000i 66 | 880.000 -592.000i 67 | 10.000 -2.000i 68 | 0.534 0.542i 69 | 10.000 -2.000i 70 | 1.009 -0.086i 71 | 72 | 10. gonio: sin cos tan asin acos atan 73 | 0.541 0.457i 74 | 0.500 0.500i 75 | 0.990 -0.250i 76 | 0.500 0.500i 77 | 0.404 0.564i 78 | 0.500 0.500i 79 | 80 | 11. gonio csc sec cot acsc asec acot 81 | 1.078 -0.912i 82 | 0.500 0.500i 83 | 0.950 0.240i 84 | 0.500 0.500i 85 | 0.839 -1.172i 86 | 0.500 0.500i 87 | 88 | 12. gonio hyperbolicus I 89 | 0.457 0.541i 90 | 0.500 0.500i 91 | 0.990 0.250i 92 | 0.500 0.500i 93 | 0.564 0.404i 94 | 0.500 0.500i 95 | 96 | 13. gonio hyperbolicus II 97 | 0.912 -1.078i 98 | 0.500 0.500i 99 | 0.950 -0.240i 100 | 0.500 0.500i 101 | 1.172 -0.839i 102 | 0.500 0.500i 103 | 104 | 14. gonio bug fix (minimal) test 105 | 3.000 4.000i 106 | 1.000 0.000i 107 | 108 | .. Complex done 109 | 521964 110 | 1.000 0.000i 111 | -------------------------------------------------------------------------------- /Complex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // 3 | // FILE: Complex.h 4 | // AUTHOR: Rob Tillaart 5 | // VERSION: 0.3.5 6 | // DATE: 2013-09-23 7 | // PURPOSE: Arduino library for Complex math 8 | // URL: https://github.com/RobTillaart/Complex 9 | // http://arduino.cc/playground/Main/ComplexMath 10 | 11 | 12 | #include "Arduino.h" 13 | #include "Printable.h" 14 | 15 | 16 | #define COMPLEX_LIB_VERSION (F("0.3.5")) 17 | 18 | 19 | class Complex: public Printable 20 | { 21 | public: 22 | Complex(const float r = 0, const float i = 0) : re(r), im(i) {}; 23 | Complex(const Complex &c) : re(c.re), im(c.im) {}; 24 | 25 | 26 | void set(const float r, const float i ) { re = r; im = i; }; 27 | void setReal(const float r) { re = r; }; 28 | void setImag(const float i ) { im = i; }; 29 | float real() const { return re; }; 30 | float imag() const { return im; }; 31 | 32 | 33 | size_t printTo(Print& p) const; 34 | 35 | 36 | void polar(const float modulus, const float phase); 37 | float phase() const { return atan2(im, re); }; 38 | float modulus() const { return hypot(re, im); }; 39 | // conjugate is the number mirrored in x-axis 40 | Complex conjugate() const { return Complex(re, -im); }; 41 | Complex reciprocal() const; 42 | 43 | 44 | bool operator == (const Complex&) const; 45 | bool operator != (const Complex&) const; 46 | 47 | 48 | Complex operator - () const; // negation 49 | 50 | 51 | Complex operator + (const Complex&) const; 52 | Complex operator - (const Complex&) const; 53 | Complex operator * (const Complex&) const; 54 | Complex operator / (const Complex&) const; 55 | 56 | Complex& operator += (const Complex&); 57 | Complex& operator -= (const Complex&); 58 | Complex& operator *= (const Complex&); 59 | Complex& operator /= (const Complex&); 60 | 61 | 62 | Complex c_sqrt() const; 63 | Complex c_sqr() const; 64 | Complex c_exp() const; 65 | Complex c_log() const; 66 | Complex c_log10() const; 67 | Complex c_pow(const Complex &) const; 68 | Complex c_logn(const Complex &) const; 69 | 70 | 71 | Complex c_sin() const; 72 | Complex c_cos() const; 73 | Complex c_tan() const; 74 | Complex c_asin() const; 75 | Complex c_acos() const; 76 | Complex c_atan() const; 77 | 78 | 79 | Complex c_csc() const; 80 | Complex c_sec() const; 81 | Complex c_cot() const; 82 | Complex c_acsc() const; 83 | Complex c_asec() const; 84 | Complex c_acot() const; 85 | 86 | 87 | Complex c_sinh() const; 88 | Complex c_cosh() const; 89 | Complex c_tanh() const; 90 | Complex c_asinh() const; 91 | Complex c_acosh() const; 92 | Complex c_atanh() const; 93 | 94 | 95 | Complex c_csch() const; 96 | Complex c_sech() const; 97 | Complex c_coth() const; 98 | Complex c_acsch() const; 99 | Complex c_asech() const; 100 | Complex c_acoth() const; 101 | 102 | 103 | protected: 104 | float re; 105 | float im; 106 | 107 | Complex gonioHelper1(const byte) const; 108 | Complex gonioHelper2(const byte) const; 109 | }; 110 | 111 | 112 | static const Complex one(1, 0); 113 | 114 | 115 | // -- END OF FILE -- 116 | 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![Arduino CI](https://github.com/RobTillaart/Complex/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) 3 | [![Arduino-lint](https://github.com/RobTillaart/Complex/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Complex/actions/workflows/arduino-lint.yml) 4 | [![JSON check](https://github.com/RobTillaart/Complex/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Complex/actions/workflows/jsoncheck.yml) 5 | [![GitHub issues](https://img.shields.io/github/issues/RobTillaart/Complex.svg)](https://github.com/RobTillaart/Complex/issues) 6 | 7 | [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Complex/blob/master/LICENSE) 8 | [![GitHub release](https://img.shields.io/github/release/RobTillaart/Complex.svg?maxAge=3600)](https://github.com/RobTillaart/Complex/releases) 9 | [![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/Complex.svg)](https://registry.platformio.org/libraries/robtillaart/Complex) 10 | 11 | 12 | # Complex 13 | 14 | Arduino library for Complex mathematical operations. 15 | 16 | 17 | ## Description 18 | 19 | This library defines the complex data type and all the common mathematical functions for it. 20 | 21 | These functions include basic = "+ - \* /" and also power and goniometric functions. 22 | 23 | The library implements the **Printable** interface so one can directly print the complex values 24 | in any stream e.g. Serial. 25 | 26 | 27 | ## Interface 28 | 29 | ```cpp 30 | #include "Complex.h" 31 | ``` 32 | 33 | See Complex.h for a full list of functions implemented. 34 | 35 | The library uses **float** for the real and imaginary part so precision is limited. 36 | Reasons are memory and performance, see also Future section below. 37 | 38 | The library implements the constant **one** as this value is often used in the code. 39 | 40 | ## Note 41 | 42 | The library has a big footprint so it fills up the memory of an UNO quite fast, 43 | especially if all functionality is used. 44 | 45 | 46 | ### Known problem 47 | 48 | Issue found in version 0.1.9 - https://github.com/RobTillaart/Arduino/issues/90 49 | Class does not compile for DUE and TEENSY 50 | Also Raspberry Pico - https://github.com/RobTillaart/Complex/issues/6 51 | 52 | Apparently the name "Complex" is already in use (reserved) by some non-AVR compilers 53 | so it won't include the Complex.h file. Problem seen on Due and Teensy3.5 54 | 55 | 56 | ### Solution 57 | 58 | - first question, do you need this complex lib if there already exists one? 59 | - Make a copy of the Complex Library and rename the folder to CComplex 60 | - Rename Complex.h to CComplex.h 61 | - Rename Complex.cpp to CComplex.cpp 62 | - change one line in CComplex.cpp to include CComplex.h 63 | - note your sketches need to include CComplex.h too. 64 | 65 | 66 | ## Future 67 | 68 | #### Must 69 | 70 | - improve documentation 71 | - tables with groups of functions? 72 | 73 | #### Should 74 | 75 | #### Could 76 | 77 | - create a (8 byte) double based variant for high precision e.g. Complex8() 78 | - Note that some platforms map double to float 79 | - others support float in hardware etc. 80 | - so expect a big difference in both memory and performance. 81 | 82 | #### Wont 83 | 84 | - create the constant **i** ?? 85 | - => expect conflicts with int i... 86 | 87 | 88 | ## Support 89 | 90 | If you appreciate my libraries, you can support the development and maintenance. 91 | Improve the quality of the libraries by providing issues and Pull Requests, or 92 | donate through PayPal or GitHub sponsors. 93 | 94 | Thank you, 95 | 96 | 97 | -------------------------------------------------------------------------------- /test/unit_test_001.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: unit_test_001.cpp 3 | // AUTHOR: Rob Tillaart 4 | // DATE: 2020-12-16 5 | // PURPOSE: unit tests for the Complex datatype Library 6 | // https://github.com/RobTillaart/Complex 7 | // https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md 8 | // 9 | 10 | // supported assertions 11 | // ---------------------------- 12 | // assertEqual(expected, actual) 13 | // assertNotEqual(expected, actual) 14 | // assertLess(expected, actual) 15 | // assertMore(expected, actual) 16 | // assertLessOrEqual(expected, actual) 17 | // assertMoreOrEqual(expected, actual) 18 | // assertTrue(actual) 19 | // assertFalse(actual) 20 | // assertNull(actual) 21 | // assertNotNull(actual) 22 | 23 | 24 | #include 25 | 26 | 27 | #include "Complex.h" 28 | 29 | 30 | unittest_setup() 31 | { 32 | fprintf(stderr, "COMPLEX_LIB_VERSION: %s\n", (char *) COMPLEX_LIB_VERSION); 33 | } 34 | 35 | 36 | unittest_teardown() 37 | { 38 | } 39 | 40 | 41 | unittest(test_constructor) 42 | { 43 | Complex c1(10.0, -2.0); 44 | Complex c2(3, 0); 45 | Complex c3(-10, 4); 46 | Complex c4(-5,-5); 47 | Complex c5; // (0, 0) 48 | 49 | assertEqual(10.0, c1.real()); 50 | assertEqual(-2.0, c1.imag()); 51 | assertEqual( 3.0, c2.real()); 52 | assertEqual( 0.0, c2.imag()); 53 | assertEqual(-10, c3.real()); 54 | assertEqual(4.0, c3.imag()); 55 | assertEqual(-5.0, c4.real()); 56 | assertEqual(-5.0, c4.imag()); 57 | assertEqual(0.0, c5.real()); 58 | assertEqual(0.0, c5.imag()); 59 | 60 | // one is a default available var. 61 | assertEqual(1.0, one.real()); 62 | assertEqual(0.0, one.imag()); 63 | 64 | // polar notation setter. 65 | c1.polar(5, PI/4); 66 | assertEqualFloat(5, c1.modulus(), 0.0001); 67 | assertEqualFloat(PI/4, c1.phase(), 0.0001); 68 | } 69 | 70 | 71 | unittest(test_basic_math) 72 | { 73 | Complex a(10.0, -2.5); 74 | Complex b(3, 1); 75 | 76 | Complex c1 = a + b; 77 | assertEqual(13, c1.real()); 78 | assertEqual(-1.5, c1.imag()); 79 | 80 | Complex c2 = a - b; 81 | assertEqual(7, c2.real()); 82 | assertEqual(-3.5, c2.imag()); 83 | 84 | Complex c3 = a * b; 85 | assertEqual(32.5, c3.real()); 86 | assertEqual(2.5, c3.imag()); 87 | 88 | Complex c4 = a / b; 89 | assertEqual(2.75, c4.real()); 90 | assertEqual(-1.75, c4.imag()); 91 | 92 | Complex c5 = -a; 93 | assertEqual(-10, c5.real()); 94 | assertEqual(2.5, c5.imag()); 95 | 96 | a += b; 97 | assertEqual(13, a.real()); 98 | assertEqual(-1.5, a.imag()); 99 | 100 | a -= b; 101 | assertEqual(10, a.real()); 102 | assertEqual(-2.5, a.imag()); 103 | 104 | a *= b; 105 | assertEqual(32.5, a.real()); 106 | assertEqual(2.5, a.imag()); 107 | 108 | a /= b; 109 | assertEqual(10, a.real()); 110 | assertEqual(-2.5, a.imag()); 111 | } 112 | 113 | 114 | unittest(test_basic_functions) 115 | { 116 | Complex a; 117 | assertEqual(0, a.real()); 118 | assertEqual(0, a.imag()); 119 | 120 | a.set(5, 34); 121 | assertEqual(5, a.real()); 122 | assertEqual(34, a.imag()); 123 | 124 | a.setReal(10); 125 | assertEqual(10, a.real()); 126 | assertEqual(34, a.imag()); 127 | 128 | a.setImag(-2.5); 129 | assertEqual(10, a.real()); 130 | assertEqual(-2.5, a.imag()); 131 | 132 | float ph = a.phase(); 133 | assertEqualFloat(-0.244979, ph, 0.0001); 134 | 135 | float mod = a.modulus(); 136 | assertEqualFloat(10.3078, mod, 0.0001); 137 | 138 | Complex conj = a.conjugate(); 139 | assertEqual(10, conj.real()); 140 | assertEqual(2.5, conj.imag()); 141 | 142 | Complex reci = a.reciprocal(); 143 | assertEqualFloat(0.0941176, reci.real(), 0.0001); 144 | assertEqualFloat(0.0235294, reci.imag(), 0.0001); 145 | 146 | reci *= a; 147 | assertEqualFloat(1.0, reci.real(), 0.0001); 148 | assertEqualFloat(0, reci.imag(), 0.0001); 149 | } 150 | 151 | 152 | unittest(test_power_functions) 153 | { 154 | Complex a(3, 4); 155 | Complex b; 156 | 157 | b = a.c_sqrt(); 158 | assertEqual(2, b.real()); 159 | assertEqual(1, b.imag()); 160 | 161 | b = a.c_sqr(); 162 | assertEqual(-7, b.real()); 163 | assertEqual(24, b.imag()); 164 | 165 | b = a.c_exp(); 166 | assertEqualFloat(-13.1288, b.real(), 0.0001); 167 | assertEqualFloat(-15.2008, b.imag(), 0.0001); 168 | 169 | b = a.c_log(); 170 | assertEqualFloat(1.60944, b.real(), 0.0001); 171 | assertEqualFloat(0.927295, b.imag(), 0.0001); 172 | 173 | b = a.c_log10(); 174 | assertEqualFloat(0.69897, b.real(), 0.0001); 175 | assertEqualFloat(0.402719, b.imag(), 0.0001); 176 | 177 | b = a.c_pow(a); 178 | assertEqualFloat(-2.99799, b.real(), 0.0001); 179 | assertEqualFloat(0.623786, b.imag(), 0.0001); 180 | 181 | b = a.c_logn(a); 182 | assertEqual(1, b.real()); 183 | assertEqual(0, b.imag()); 184 | } 185 | 186 | 187 | unittest(test_gonio_functions_I) 188 | { 189 | Complex a(3, 4); 190 | Complex b; 191 | 192 | b = a.c_sin(); 193 | assertEqualFloat(3.85374, b.real(), 0.0001); 194 | assertEqualFloat(-27.0168, b.imag(), 0.0001); 195 | 196 | b = a.c_cos(); 197 | assertEqualFloat(-27.0349, b.real(), 0.0001); 198 | assertEqualFloat(-3.85115, b.imag(), 0.0001); 199 | 200 | b = a.c_tan(); 201 | assertEqualFloat(-0.000187318, b.real(), 0.0001); 202 | assertEqualFloat(0.999356, b.imag(), 0.0001); 203 | 204 | b = a.c_asin(); 205 | assertEqualFloat(0.633984, b.real(), 0.0001); 206 | assertEqualFloat(2.30551, b.imag(), 0.0001); 207 | 208 | b = a.c_acos(); 209 | assertEqualFloat(0.936813, b.real(), 0.0001); 210 | assertEqualFloat(-2.30551, b.imag(), 0.0001); 211 | 212 | b = a.c_atan(); 213 | assertEqualFloat(1.44831, b.real(), 0.0001); 214 | assertEqualFloat(0.158997, b.imag(), 0.0001); 215 | } 216 | 217 | 218 | unittest_main() 219 | 220 | 221 | // -- END OF FILE -- 222 | 223 | -------------------------------------------------------------------------------- /examples/complex/complex.ino: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: complex.ino 3 | // AUTHOR: Rob Tillaart 4 | // DATE: 2013-09-23 5 | // PURPOSE: demo complex 6 | // URL: https://github.com/RobTillaart/Complex 7 | // 8 | // Serial.print(Complex) supported since 0.1.05 9 | 10 | 11 | #include "Complex.h" 12 | 13 | 14 | void setup() 15 | { 16 | Serial.begin(115200); 17 | Serial.println(); 18 | Serial.println(__FILE__); 19 | Serial.print("COMPLEX_LIB_VERSION: "); 20 | Serial.println(COMPLEX_LIB_VERSION); 21 | Serial.println(); 22 | 23 | Serial.println("\n1. Print Complex, set, real, imag"); 24 | 25 | Complex c1(10.0, -2.0); 26 | Complex c2(3, 0); 27 | Complex c3(-10, 4); 28 | Complex c4(-5,-5); 29 | Complex c5(0, 0); 30 | 31 | Serial.println(one); 32 | Serial.println(c1); 33 | Serial.println(c2); 34 | Serial.println(c3); 35 | Serial.println(c4); 36 | c3.set(0,0); 37 | Serial.println(c3); 38 | Serial.println(c3.real()); 39 | Serial.println(c3.imag()); 40 | 41 | Serial.println("\n2. == != "); 42 | c5 = c1; 43 | if (c5 == c1) Serial.println("ok :)"); 44 | else Serial.println(" fail :("); 45 | c5 = c1 + 1; 46 | if (c5 != c1) Serial.println("ok :)"); 47 | else Serial.println(" fail :("); 48 | c5 = 3; 49 | if (c5 == 3) Serial.println("ok :)"); 50 | else Serial.println(" fail :("); 51 | 52 | 53 | Serial.println("\n3. negation - "); 54 | c5 = -c1; 55 | Serial.println(c5); 56 | c5 = -c5; 57 | Serial.println(c5); 58 | if (c5 == c1) Serial.println("ok :)"); 59 | else Serial.println(" fail :("); 60 | 61 | 62 | Serial.println("\n4. + - "); 63 | c5 = c1 + c2; 64 | Serial.println(c5); 65 | c5 = c1 + 3; 66 | Serial.println(c5); 67 | c5 = c1 - c2; 68 | Serial.println(c5); 69 | c5 = c1 - 3; 70 | Serial.println(c5); 71 | 72 | 73 | Serial.println("\n5. * / "); 74 | c5 = c1 * c2; 75 | Serial.println(c5); 76 | c5 = c5 * 3; 77 | Serial.println(c5); 78 | c5 = c5 / c2; 79 | Serial.println(c5); 80 | c5 = c5 / 3; 81 | Serial.println(c5); 82 | 83 | c5 = c1 / c2 * c2; 84 | Serial.println(c5); 85 | c5 = c1 * c4 / c4; 86 | Serial.println(c5); 87 | 88 | 89 | Serial.println("\n6. assign += -= *= /="); 90 | c5 = c1; 91 | c5 += c1; 92 | Serial.println(c5); 93 | c5 += 3; 94 | Serial.println(c5); 95 | c5 -= c1; 96 | Serial.println(c5); 97 | c5 -= 3; 98 | Serial.println(c5); 99 | c5 *= c1; 100 | Serial.println(c5); 101 | c5 *= 3; 102 | Serial.println(c5); 103 | c5 /= c1; 104 | Serial.println(c5); 105 | c5 /= 3; 106 | Serial.println(c5); 107 | 108 | 109 | Serial.println("\n7. phase modulus polar"); 110 | Serial.println(c1); 111 | double m = c1.modulus(); 112 | Serial.println(m); 113 | double p = c1.phase(); 114 | Serial.println(p); 115 | c5.polar(m, p); 116 | Serial.println(c5); 117 | 118 | 119 | Serial.println("\n8. conjugate reciprocal"); 120 | c5 = c1.conjugate(); 121 | Serial.println(c5); 122 | c5 = c5.conjugate(); 123 | Serial.println(c5); 124 | c5 = c1.reciprocal(); 125 | Serial.println(c5); 126 | c5 = c5.reciprocal(); 127 | Serial.println(c5); 128 | 129 | Serial.println("\n9. power: exp log pow sqrt sqr logn log10"); 130 | c5 = c1.c_sqr(); 131 | Serial.println(c5); 132 | c5 = c1.c_exp(); 133 | Serial.println(c5); 134 | c5 = c5.c_log(); 135 | Serial.println(c5); 136 | c5 = c1.c_pow(2); 137 | Serial.println(c5); 138 | c5 = c5.c_sqrt(); 139 | Serial.println(c5); 140 | c5 = c5.c_sqr(); 141 | Serial.println(c5); 142 | c5 = c1.c_pow(c2); 143 | Serial.println(c5); 144 | c5 = c5.c_pow(c2.reciprocal()); 145 | Serial.println(c5); 146 | c5 = c5.c_logn(c4); 147 | Serial.println(c5); 148 | c5 = c4.c_pow(c5); 149 | Serial.println(c5); 150 | c5 = c5.c_log10(); 151 | Serial.println(c5); 152 | 153 | Serial.println("\n10. gonio: sin cos tan asin acos atan"); 154 | c1.set(0.5, 0.5); 155 | c5 = c1.c_sin(); 156 | Serial.println(c5); 157 | c5 = c5.c_asin(); 158 | Serial.println(c5); 159 | c5 = c1.c_cos(); 160 | Serial.println(c5); 161 | c5 = c5.c_acos(); 162 | Serial.println(c5); 163 | c5 = c1.c_tan(); 164 | Serial.println(c5); 165 | c5 = c5.c_atan(); 166 | Serial.println(c5); 167 | 168 | Serial.println("\n11. gonio csc sec cot acsc asec acot"); 169 | c1.set(0.5, 0.5); 170 | c5 = c1.c_csc(); 171 | Serial.println(c5); 172 | c5 = c5.c_acsc(); 173 | Serial.println(c5); 174 | c5 = c1.c_sec(); 175 | Serial.println(c5); 176 | c5 = c5.c_asec(); 177 | Serial.println(c5); 178 | c5 = c1.c_cot(); 179 | Serial.println(c5); 180 | c5 = c5.c_acot(); 181 | Serial.println(c5); 182 | 183 | Serial.println("\n12. gonio hyperbolicus I "); 184 | c1.set(0.5, 0.5); 185 | c5 = c1.c_sinh(); 186 | Serial.println(c5); 187 | c5 = c5.c_asinh(); 188 | Serial.println(c5); 189 | c5 = c1.c_cosh(); 190 | Serial.println(c5); 191 | c5 = c5.c_acosh(); 192 | Serial.println(c5); 193 | c5 = c1.c_tanh(); 194 | Serial.println(c5); 195 | c5 = c5.c_atanh(); 196 | Serial.println(c5); 197 | 198 | Serial.println("\n13. gonio hyperbolicus II "); 199 | c1.set(0.5, 0.5); 200 | c5 = c1.c_csch(); 201 | Serial.println(c5); 202 | c5 = c5.c_acsch(); 203 | Serial.println(c5); 204 | c5 = c1.c_sech(); 205 | Serial.println(c5); 206 | c5 = c5.c_asech(); 207 | Serial.println(c5); 208 | c5 = c1.c_coth(); 209 | Serial.println(c5); 210 | c5 = c5.c_acoth(); 211 | Serial.println(c5); 212 | 213 | Serial.println("\n14. gonio bug fix (minimal) test"); 214 | c1.set(3, 4); 215 | Serial.println(c1); 216 | c2 = c1.c_sin(); 217 | c2 = c2 * c2; 218 | c3 = c1.c_cos(); 219 | c3 = c3 * c3; 220 | Serial.println(c2 + c3); // should print 1, 0i 221 | 222 | Serial.println("\n.. Complex done"); 223 | 224 | uint32_t start = micros(); 225 | for (int i = 0; i < 1000; i++) 226 | { 227 | c5 = c5.c_csc(); 228 | } 229 | uint32_t dur = micros() - start; 230 | Serial.println(dur); 231 | Serial.println(one); 232 | } 233 | 234 | 235 | void loop() 236 | { 237 | } 238 | 239 | 240 | // -- END OF FILE -- 241 | 242 | -------------------------------------------------------------------------------- /Complex.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: Complex.cpp 3 | // AUTHOR: Rob Tillaart 4 | // VERSION: 0.3.5 5 | // DATE: 2013-09-23 6 | // PURPOSE: Arduino library for Complex math 7 | // URL: https://github.com/RobTillaart/Complex 8 | // http://arduino.cc/playground/Main/ComplexMath 9 | 10 | 11 | #include "Complex.h" 12 | 13 | 14 | // PRINTING 15 | size_t Complex::printTo(Print& p) const 16 | { 17 | size_t n = 0; 18 | n += p.print(re, 3); 19 | n += p.print(' '); 20 | n += p.print(im, 3); 21 | n += p.print('i'); 22 | return n; 23 | }; 24 | 25 | 26 | void Complex::polar(const float modulus, const float phase) 27 | { 28 | re = modulus * cos(phase); 29 | im = modulus * sin(phase); 30 | } 31 | 32 | 33 | Complex Complex::reciprocal() const 34 | { 35 | float f = 1.0 / (re * re + im * im); 36 | float r = re * f; 37 | float i = -im * f; 38 | return Complex(r, i); 39 | } 40 | 41 | // 42 | // EQUALITIES 43 | // 44 | bool Complex::operator == (const Complex &c) const 45 | { 46 | return (re == c.re) && (im == c.im); 47 | } 48 | 49 | 50 | bool Complex::operator != (const Complex &c) const 51 | { 52 | return (re != c.re) || (im != c.im); 53 | } 54 | 55 | 56 | // 57 | // NEGATE 58 | // 59 | Complex Complex::operator - () const 60 | { 61 | return Complex(-re, -im); 62 | } 63 | 64 | 65 | // 66 | // BASIC MATH 67 | // 68 | Complex Complex::operator + (const Complex &c) const 69 | { 70 | return Complex(re + c.re, im + c.im); 71 | } 72 | 73 | 74 | Complex Complex::operator - (const Complex &c) const 75 | { 76 | return Complex(re - c.re, im - c.im); 77 | } 78 | 79 | 80 | Complex Complex::operator * (const Complex &c) const 81 | { 82 | float r = re * c.re - im * c.im; 83 | float i = re * c.im + im * c.re; 84 | return Complex(r, i); 85 | } 86 | 87 | 88 | Complex Complex::operator / (const Complex &c) const 89 | { 90 | float f = 1.0/(c.re * c.re + c.im * c.im); 91 | float r = (re * c.re + im * c.im) * f; 92 | float i = (im * c.re - re * c.im) * f; 93 | return Complex(r, i); 94 | } 95 | 96 | 97 | Complex& Complex::operator += (const Complex &c) 98 | { 99 | re += c.re; 100 | im += c.im; 101 | return *this; 102 | } 103 | 104 | 105 | Complex& Complex::operator -= (const Complex &c) 106 | { 107 | re -= c.re; 108 | im -= c.im; 109 | return *this; 110 | } 111 | 112 | 113 | Complex& Complex::operator *= (const Complex &c) 114 | { 115 | float r = re * c.re - im * c.im; 116 | float i = re * c.im + im * c.re; 117 | re = r; 118 | im = i; 119 | return *this; 120 | } 121 | 122 | 123 | Complex& Complex::operator /= (const Complex &c) 124 | { 125 | float f = 1.0/(c.re * c.re + c.im * c.im); 126 | float r = (re * c.re + im * c.im) * f; 127 | float i = (im * c.re - re * c.im) * f; 128 | re = r; 129 | im = i; 130 | return *this; 131 | } 132 | 133 | 134 | // 135 | // POWER FUNCTIONS 136 | // 137 | Complex Complex::c_sqr() const 138 | { 139 | float r = re * re - im * im; 140 | float i = 2 * re * im; 141 | return Complex(r, i); 142 | } 143 | 144 | 145 | Complex Complex::c_sqrt() const 146 | { 147 | float m = modulus(); 148 | float r = sqrt(0.5 * (m + re)); 149 | float i = sqrt(0.5 * (m - re)); 150 | if (im < 0) i = -i; 151 | return Complex(r, i); 152 | } 153 | 154 | 155 | Complex Complex::c_exp() const 156 | { 157 | float e = exp(re); 158 | return Complex(e * cos(im), e * sin(im)); 159 | } 160 | 161 | 162 | Complex Complex::c_log() const 163 | { 164 | float m = modulus(); 165 | float p = phase(); 166 | if (p > PI) p -= 2 * PI; 167 | return Complex(log(m), p); 168 | } 169 | 170 | 171 | Complex Complex::c_pow(const Complex &c) const 172 | { 173 | Complex t = c_log(); 174 | t = t * c; 175 | return t.c_exp(); 176 | } 177 | 178 | 179 | Complex Complex::c_logn(const Complex &c) const 180 | { 181 | Complex t = c; 182 | return c_log()/t.c_log(); 183 | } 184 | 185 | 186 | Complex Complex::c_log10() const 187 | { 188 | return c_logn(10); 189 | } 190 | 191 | 192 | // 193 | // GONIO I - SIN COS TAN 194 | // 195 | Complex Complex::c_sin() const 196 | { 197 | return Complex(sin(re) * cosh(im), cos(re) * sinh(im)); 198 | } 199 | 200 | 201 | Complex Complex::c_cos() const 202 | { 203 | return Complex(cos(re) * cosh(im), -sin(re) * sinh(im)); 204 | } 205 | 206 | 207 | Complex Complex::c_tan() const 208 | { 209 | /* faster but 350 bytes longer!! 210 | float s = sin(re); 211 | float c = cos(re); 212 | float sh = sinh(im); 213 | float ch = cosh(im); 214 | // return Complex(s*ch, c*sh) / Complex(c*ch, -s*sh); 215 | float r0 = s*ch; 216 | float i0 = c*sh; 217 | float cre = c*ch; 218 | float cim = -s*sh; 219 | float f = 1.0/(cre*cre + cim*cim); 220 | float r = r0 * cre + i0 * cim; 221 | float i = r0 * cim - i0 * cre; 222 | return Complex(r * f, -i * f); 223 | */ 224 | return c_sin() / c_cos(); 225 | } 226 | 227 | 228 | Complex Complex::gonioHelper1(const byte mode) const 229 | { 230 | Complex c = (one - this->c_sqr()).c_sqrt(); 231 | if (mode == 0) 232 | { 233 | c = c + *this * Complex(0,-1); 234 | } 235 | else 236 | { 237 | c = *this + c * Complex(0,-1); 238 | } 239 | c = c.c_log() * Complex(0,1); 240 | return c; 241 | } 242 | 243 | 244 | Complex Complex::c_asin() const 245 | { 246 | return gonioHelper1(0); 247 | } 248 | 249 | 250 | Complex Complex::c_acos() const 251 | { 252 | return gonioHelper1(1); 253 | } 254 | 255 | 256 | Complex Complex::c_atan() const 257 | { 258 | return (Complex(0,-1) * (Complex(re, im - 1)/Complex(-re, -im - 1)).c_log()) * 0.5; 259 | } 260 | 261 | 262 | // 263 | // GONIO II - CSC SEC COT 264 | // 265 | Complex Complex::c_csc() const 266 | { 267 | return one / c_sin(); 268 | } 269 | 270 | 271 | Complex Complex::c_sec() const 272 | { 273 | return one / c_cos(); 274 | } 275 | 276 | 277 | Complex Complex::c_cot() const 278 | { 279 | return one / c_tan(); 280 | } 281 | 282 | 283 | Complex Complex::c_acsc() const 284 | { 285 | return (one / *this).c_asin(); 286 | } 287 | 288 | 289 | Complex Complex::c_asec() const 290 | { 291 | return (one / *this).c_acos(); 292 | } 293 | 294 | 295 | Complex Complex::c_acot() const 296 | { 297 | return (one / *this).c_atan(); 298 | } 299 | 300 | 301 | // 302 | // GONIO HYPERBOLICUS I 303 | // 304 | Complex Complex::c_sinh() const 305 | { 306 | return Complex(cos(im) * sinh(re), sin(im) * cosh(re)); 307 | } 308 | 309 | 310 | Complex Complex::c_cosh() const 311 | { 312 | return Complex(cos(im) * cosh(re), sin(im) * sinh(re)); 313 | } 314 | 315 | 316 | Complex Complex::c_tanh() const 317 | { 318 | return c_sinh() / c_cosh(); 319 | } 320 | 321 | 322 | Complex Complex::gonioHelper2(const byte mode) const 323 | { 324 | Complex c = c_sqr(); 325 | if (mode == 0) 326 | { 327 | c += 1; 328 | } 329 | else 330 | { 331 | c -= 1; 332 | } 333 | c = (*this + c.c_sqrt()).c_log(); 334 | return c; 335 | } 336 | 337 | 338 | Complex Complex::c_asinh() const 339 | { 340 | return gonioHelper2(0); 341 | } 342 | 343 | 344 | Complex Complex::c_acosh() const 345 | { 346 | return gonioHelper2(1); 347 | } 348 | 349 | 350 | Complex Complex::c_atanh() const 351 | { 352 | Complex c = (*this + one).c_log(); 353 | c = c - (-(*this - one)).c_log(); 354 | return c * 0.5; 355 | } 356 | 357 | 358 | // 359 | // GONIO HYPERBOLICUS II 360 | // 361 | Complex Complex::c_csch() const 362 | { 363 | return one / c_sinh(); 364 | } 365 | 366 | 367 | Complex Complex::c_sech() const 368 | { 369 | return one / c_cosh(); 370 | } 371 | 372 | 373 | Complex Complex::c_coth() const 374 | { 375 | return one / c_tanh(); 376 | } 377 | 378 | 379 | Complex Complex::c_acsch() const 380 | { 381 | return (one / *this).c_asinh(); 382 | } 383 | 384 | 385 | Complex Complex::c_asech() const 386 | { 387 | return (one / *this).c_acosh(); 388 | } 389 | 390 | 391 | Complex Complex::c_acoth() const 392 | { 393 | return (one / *this).c_atanh(); 394 | } 395 | 396 | 397 | // --- END OF FILE --- 398 | 399 | -------------------------------------------------------------------------------- /examples/performance/performance.ino: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: performance.ino 3 | // AUTHOR: Rob Tillaart 4 | // DATE: 2013-09-23 5 | // PURPOSE: test complex math 6 | // URL: https://github.com/RobTillaart/Complex 7 | // 8 | // Serial.print(Complex) supported since 0.1.05 9 | 10 | 11 | #include "Complex.h" 12 | 13 | unsigned long start, stop, total; 14 | double re, im, m, p; 15 | 16 | 17 | void setup() 18 | { 19 | Serial.begin(115200); 20 | Serial.println(); 21 | Serial.println(__FILE__); 22 | Serial.print("COMPLEX_LIB_VERSION: "); 23 | Serial.println(COMPLEX_LIB_VERSION); 24 | Serial.println(); 25 | Serial.print(" Complex numbers performance test for Arduino: "); 26 | delay(100); 27 | 28 | start = micros(); 29 | Complex c1(10.0, -2.0); 30 | Complex c2(3, 0); 31 | Complex c3(-10, 4); 32 | Complex c4(-5,-5); 33 | Complex c5(0, 0); 34 | stop = micros(); 35 | Serial.print("5 constructors\t"); 36 | Serial.println(stop - start); 37 | total += (stop - start); 38 | delay(10); 39 | 40 | start = micros(); 41 | for(uint8_t i=0; i< 100; i++) c3.set(0,0); 42 | stop = micros(); 43 | Serial.print("set(0,0)\t"); 44 | Serial.println(stop - start); 45 | total += (stop - start); 46 | delay(10); 47 | 48 | start = micros(); 49 | for(uint8_t i=0; i< 100; i++) c5 = c1 + 1; 50 | stop = micros(); 51 | Serial.print("c1 + 1 \t"); 52 | Serial.println(stop - start); 53 | total += (stop - start); 54 | delay(10); 55 | 56 | start = micros(); 57 | for(uint8_t i=0; i< 100; i++) c5 = c1 + c2; 58 | stop = micros(); 59 | Serial.print("c1 + c2\t\t"); 60 | Serial.println(stop - start); 61 | total += (stop - start); 62 | delay(10); 63 | 64 | start = micros(); 65 | for(uint8_t i=0; i< 100; i++) c5 += c2; 66 | stop = micros(); 67 | Serial.print("+= c2\t\t"); 68 | Serial.println(stop - start); 69 | total += (stop - start); 70 | delay(10); 71 | 72 | start = micros(); 73 | for(uint8_t i=0; i< 100; i++) c5 = -c1; 74 | stop = micros(); 75 | Serial.print("c5 = -c1\t"); 76 | Serial.println(stop - start); 77 | total += (stop - start); 78 | delay(10); 79 | 80 | start = micros(); 81 | for(uint8_t i=0; i< 100; i++) c5 = c1 - 3; 82 | stop = micros(); 83 | Serial.print("c1 - 3\t\t"); 84 | Serial.println(stop - start); 85 | total += (stop - start); 86 | delay(10); 87 | 88 | start = micros(); 89 | for(uint8_t i=0; i< 100; i++) c5 = c1 - c2; 90 | stop = micros(); 91 | Serial.print("c1 - c2\t\t"); 92 | Serial.println(stop - start); 93 | total += (stop - start); 94 | delay(10); 95 | 96 | start = micros(); 97 | for(uint8_t i=0; i< 100; i++) c5 -= c2; 98 | stop = micros(); 99 | Serial.print("c5 -= c2\t"); 100 | Serial.println(stop - start); 101 | total += (stop - start); 102 | delay(10); 103 | 104 | start = micros(); 105 | for(uint8_t i=0; i< 100; i++) c5 = c1 * 3; 106 | stop = micros(); 107 | Serial.print("c1 * 3\t\t"); 108 | Serial.println(stop - start); 109 | total += (stop - start); 110 | delay(10); 111 | 112 | start = micros(); 113 | for(uint8_t i=0; i< 100; i++) c5 = c1 * c2; 114 | stop = micros(); 115 | Serial.print("c1 * c2\t\t"); 116 | Serial.println(stop - start); 117 | total += (stop - start); 118 | delay(10); 119 | 120 | start = micros(); 121 | for(uint8_t i=0; i< 100; i++) c5 *= c2; 122 | stop = micros(); 123 | Serial.print("c5 *= c2\t"); 124 | Serial.println(stop - start); 125 | total += (stop - start); 126 | delay(10); 127 | 128 | start = micros(); 129 | for(uint8_t i=0; i< 100; i++) c5 = c1 / 3; 130 | stop = micros(); 131 | Serial.print("c1 / 3\t\t"); 132 | Serial.println(stop - start); 133 | total += (stop - start); 134 | delay(10); 135 | 136 | start = micros(); 137 | for(uint8_t i=0; i< 100; i++) c5 = c1 / c2; 138 | stop = micros(); 139 | Serial.print("c1 / c2\t\t"); 140 | Serial.println(stop - start); 141 | total += (stop - start); 142 | delay(10); 143 | 144 | start = micros(); 145 | for(uint8_t i=0; i< 100; i++) c5 /= c2; 146 | stop = micros(); 147 | Serial.print("c5 /= c2\t"); 148 | Serial.println(stop - start); 149 | total += (stop - start); 150 | delay(10); 151 | 152 | Serial.println(); 153 | delay(10); 154 | 155 | start = micros(); 156 | for(uint8_t i=0; i< 100; i++) re = c1.real(); 157 | stop = micros(); 158 | Serial.print("real()\t\t"); 159 | Serial.println(stop - start); 160 | total += (stop - start); 161 | delay(10); 162 | 163 | start = micros(); 164 | for(uint8_t i=0; i< 100; i++) im = c1.imag(); 165 | stop = micros(); 166 | Serial.print("imag()\t\t"); 167 | Serial.println(stop - start); 168 | total += (stop - start); 169 | delay(10); 170 | 171 | start = micros(); 172 | for(uint8_t i=0; i< 100; i++) m = c1.modulus(); 173 | stop = micros(); 174 | Serial.print("modulus()\t"); 175 | Serial.println(stop - start); 176 | total += (stop - start); 177 | delay(10); 178 | 179 | start = micros(); 180 | for(uint8_t i=0; i< 100; i++) p = c1.phase(); 181 | stop = micros(); 182 | Serial.print("phase\t\t"); 183 | Serial.println(stop - start); 184 | total += (stop - start); 185 | delay(10); 186 | 187 | start = micros(); 188 | for(uint8_t i=0; i< 100; i++) c5.polar(m, p); 189 | stop = micros(); 190 | Serial.print("polar()\t\t"); 191 | Serial.println(stop - start); 192 | total += (stop - start); 193 | delay(10); 194 | 195 | start = micros(); 196 | for(uint8_t i=0; i< 100; i++) c5 = c1.conjugate(); 197 | stop = micros(); 198 | Serial.print("conjugate()\t"); 199 | Serial.println(stop - start); 200 | total += (stop - start); 201 | delay(10); 202 | 203 | start = micros(); 204 | for(uint8_t i=0; i< 100; i++) c5 = c1.reciprocal(); 205 | stop = micros(); 206 | Serial.print("reciprocal();\t"); 207 | Serial.println(stop - start); 208 | total += (stop - start); 209 | 210 | Serial.println(); 211 | delay(10); 212 | 213 | start = micros(); 214 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_sqr(); 215 | stop = micros(); 216 | Serial.print("c_sqr()\t\t"); 217 | Serial.println(stop - start); 218 | total += (stop - start); 219 | delay(10); 220 | 221 | start = micros(); 222 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_exp(); 223 | stop = micros(); 224 | Serial.print("c_exp()\t\t"); 225 | Serial.println(stop - start); 226 | total += (stop - start); 227 | delay(10); 228 | 229 | start = micros(); 230 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_log(); 231 | stop = micros(); 232 | Serial.print("c_log()\t\t"); 233 | Serial.println(stop - start); 234 | total += (stop - start); 235 | delay(10); 236 | 237 | start = micros(); 238 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_pow(2); 239 | stop = micros(); 240 | Serial.print("c_pow(2)\t"); 241 | Serial.println(stop - start); 242 | total += (stop - start); 243 | delay(10); 244 | 245 | start = micros(); 246 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_sqrt(); 247 | stop = micros(); 248 | Serial.print("c_sqrt()\t"); 249 | Serial.println(stop - start); 250 | total += (stop - start); 251 | delay(10); 252 | 253 | start = micros(); 254 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_logn(c4); 255 | stop = micros(); 256 | Serial.print("c_logn(c4)\t"); 257 | Serial.println(stop - start); 258 | total += (stop - start); 259 | delay(10); 260 | 261 | start = micros(); 262 | for(uint8_t i=0; i< 100; i++) c5 = c4.c_pow(c5); 263 | stop = micros(); 264 | Serial.print("c_pow(c5)\t"); 265 | Serial.println(stop - start); 266 | total += (stop - start); 267 | delay(10); 268 | 269 | start = micros(); 270 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_log10(); 271 | stop = micros(); 272 | Serial.print("c_log10()\t"); 273 | Serial.println(stop - start); 274 | total += (stop - start); 275 | delay(10); 276 | 277 | Serial.println(); 278 | c1.set(0.5, 0.5); 279 | delay(10); 280 | 281 | start = micros(); 282 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_sin(); 283 | stop = micros(); 284 | Serial.print("c_sin()\t\t"); 285 | Serial.println(stop - start); 286 | total += (stop - start); 287 | delay(10); 288 | 289 | start = micros(); 290 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_asin(); 291 | stop = micros(); 292 | Serial.print("c_asin()\t"); 293 | Serial.println(stop - start); 294 | delay(10); 295 | 296 | start = micros(); 297 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_cos(); 298 | stop = micros(); 299 | Serial.print("c_cos()\t\t"); 300 | Serial.println(stop - start); 301 | total += (stop - start); 302 | delay(10); 303 | 304 | start = micros(); 305 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_acos(); 306 | stop = micros(); 307 | Serial.print("c_acos()\t"); 308 | Serial.println(stop - start); 309 | total += (stop - start); 310 | delay(10); 311 | 312 | start = micros(); 313 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_tan(); 314 | stop = micros(); 315 | Serial.print("c_tan()\t\t"); 316 | Serial.println(stop - start); 317 | total += (stop - start); 318 | delay(10); 319 | 320 | start = micros(); 321 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_atan(); 322 | stop = micros(); 323 | Serial.print("c_atan()\t"); 324 | Serial.println(stop - start); 325 | total += (stop - start); 326 | delay(10); 327 | 328 | Serial.println(); 329 | c1.set(0.5, 0.5); 330 | delay(10); 331 | 332 | start = micros(); 333 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_csc(); 334 | stop = micros(); 335 | Serial.print("c_csc()\t\t"); 336 | Serial.println(stop - start); 337 | total += (stop - start); 338 | delay(10); 339 | 340 | start = micros(); 341 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_acsc(); 342 | stop = micros(); 343 | Serial.print("c_acsc()\t"); 344 | Serial.println(stop - start); 345 | total += (stop - start); 346 | delay(10); 347 | 348 | start = micros(); 349 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_sec(); 350 | stop = micros(); 351 | Serial.print("c_sec()\t\t"); 352 | Serial.println(stop - start); 353 | total += (stop - start); 354 | delay(10); 355 | 356 | start = micros(); 357 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_asec(); 358 | stop = micros(); 359 | Serial.print("c_asec()\t"); 360 | Serial.println(stop - start); 361 | total += (stop - start); 362 | delay(10); 363 | 364 | start = micros(); 365 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_cot(); 366 | stop = micros(); 367 | Serial.print("c_cot()\t\t"); 368 | Serial.println(stop - start); 369 | total += (stop - start); 370 | delay(10); 371 | 372 | start = micros(); 373 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_acot(); 374 | stop = micros(); 375 | Serial.print("c_acot()\t"); 376 | Serial.println(stop - start); 377 | total += (stop - start); 378 | delay(10); 379 | 380 | Serial.println(); 381 | c1.set(0.5, 0.5); 382 | delay(10); 383 | 384 | start = micros(); 385 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_sinh(); 386 | stop = micros(); 387 | Serial.print("c_sinh()\t"); 388 | Serial.println(stop - start); 389 | total += (stop - start); 390 | delay(10); 391 | 392 | start = micros(); 393 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_asinh(); 394 | stop = micros(); 395 | Serial.print("c_asinh()\t"); 396 | Serial.println(stop - start); 397 | total += (stop - start); 398 | delay(10); 399 | 400 | start = micros(); 401 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_cosh(); 402 | stop = micros(); 403 | Serial.print("c_cosh()\t"); 404 | Serial.println(stop - start); 405 | total += (stop - start); 406 | delay(10); 407 | 408 | start = micros(); 409 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_acosh(); 410 | stop = micros(); 411 | Serial.print("c_acosh()\t"); 412 | Serial.println(stop - start); 413 | total += (stop - start); 414 | delay(10); 415 | 416 | start = micros(); 417 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_tanh(); 418 | stop = micros(); 419 | Serial.print("c_tanh()\t"); 420 | Serial.println(stop - start); 421 | total += (stop - start); 422 | delay(10); 423 | 424 | start = micros(); 425 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_atanh(); 426 | stop = micros(); 427 | Serial.print("c_atanh()\t"); 428 | Serial.println(stop - start); 429 | total += (stop - start); 430 | delay(10); 431 | 432 | Serial.println(); 433 | c1.set(0.5, 0.5); 434 | delay(10); 435 | 436 | start = micros(); 437 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_csch(); 438 | stop = micros(); 439 | Serial.print("c_csch()\t"); 440 | Serial.println(stop - start); 441 | total += (stop - start); 442 | delay(10); 443 | 444 | start = micros(); 445 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_acsch(); 446 | stop = micros(); 447 | Serial.print("c_acsch()\t"); 448 | Serial.println(stop - start); 449 | total += (stop - start); 450 | delay(10); 451 | 452 | start = micros(); 453 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_sech(); 454 | stop = micros(); 455 | Serial.print("c_sech()\t"); 456 | Serial.println(stop - start); 457 | total += (stop - start); 458 | delay(10); 459 | 460 | start = micros(); 461 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_asech(); 462 | stop = micros(); 463 | Serial.print("c_asech()\t"); 464 | Serial.println(stop - start); 465 | total += (stop - start); 466 | delay(10); 467 | 468 | start = micros(); 469 | for(uint8_t i=0; i< 100; i++) c5 = c1.c_coth(); 470 | stop = micros(); 471 | Serial.print("c_coth()\t"); 472 | Serial.println(stop - start); 473 | total += (stop - start); 474 | delay(10); 475 | 476 | start = micros(); 477 | for(uint8_t i=0; i< 100; i++) c5 = c5.c_acoth(); 478 | stop = micros(); 479 | Serial.print("c_acoth()\t"); 480 | Serial.println(stop - start); 481 | total += (stop - start); 482 | delay(10); 483 | 484 | Serial.println(); 485 | Serial.println(total); 486 | Serial.println("\n.. Complex done"); 487 | } 488 | 489 | 490 | void loop() 491 | { 492 | } 493 | 494 | 495 | // -- END OF FILE -- 496 | 497 | --------------------------------------------------------------------------------