summary refs log tree commit diff stats
path: root/lib/pure/complex.nim
Commit message (Collapse)AuthorAgeFilesLines
* Add Complex version of almostEqual function (#23549)Angel Ezquerra2024-05-081-3/+18
| | | | | | | | This adds a version of `almostEqual` (which was already available for floats) thata works with `Complex[SomeFloat]`. Proof that this is needed is that the first thing that the complex.nim runnable examples block did before this commit was define (an incomplete) `almostEqual` function that worked with complex values.
* Additional speed ups of complex.pow (#23264)Angel Ezquerra2024-01-291-8/+25
| | | | | | | | | | | | | | | | | | | | | This PR speeds up complex.pow when both base and exponent are real; when only the exponent is real; and when the base is Euler's number. These are some pretty common cases which appear in many formulas. The speed ups are pretty significant. According to my measurements (using the timeit library) when both base and exponent are real the speedup is ~2x; when only the exponent is real it is ~1.5x and when the base is Euler's number it is ~2x. There is no measurable difference when using other exponents which makes sense since I refactored the code a little to reduce the total number of branches that are needed to get to the final "fallback" branch, and those branches have less comparisons. Anecdotally the fallback case feels slightly faster, but the improvement is so small that I cannot claim an improvement. If it is there it is perhaps in the order of 3 or 4%. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Speed up complex.pow when the exponent is 2.0 or 0.5 (#23237)Angel Ezquerra2024-01-201-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR speeds up the calculation of the power of a complex number when the exponent is 2.0 or 0.5 (i.e the square and the square root of a complex number). These are probably two of (if not) the most common exponents. The speed up that is achieved according to my measurements (using the timeit library) when the exponent is set to 2.0 or 0.5 is > x7, while there is no measurable difference when using other exponents. For the record, this is the function I used to mesure the performance: ```nim import std/complex import timeit proc calculcatePows(v: seq[Complex], factor: Complex): seq[Complex] {.noinit, discardable.} = result = newSeq[Complex](v.len) for n in 0 ..< v.len: result[n] = pow(v[n], factor) let v: seq[Complex64] = collect: for n in 0 ..< 1000: complex(float(n)) echo timeGo(calculcatePows(v, complex(1.5))) echo timeGo(calculcatePows(v, complex(0.5))) echo timeGo(calculcatePows(v, complex(2.0))) ``` Which with the original code got: > [177μs 857.03ns] ± [1μs 234.85ns] per loop (mean ± std. dev. of 7 runs, 1000 loops each) > [128μs 217.92ns] ± [1μs 630.93ns] per loop (mean ± std. dev. of 7 runs, 1000 loops each) > [136μs 220.16ns] ± [3μs 475.56ns] per loop (mean ± std. dev. of 7 runs, 1000 loops each) While with the improved code got: > [176μs 884.30ns] ± [1μs 307.30ns] per loop (mean ± std. dev. of 7 runs, 1000 loops each) > [23μs 160.79ns] ± [340.18ns] per loop (mean ± std. dev. of 7 runs, 10000 loops each) > [19μs 93.29ns] ± [1μs 128.92ns] per loop (mean ± std. dev. of 7 runs, 10000 loops each) That is, the new optimized path is 5.6 (23 vs 128 us per loop) to 7.16 times faster (19 vs 136 us per loop), while the non-optimized path takes the same time as the original code.
* 'j' format specifier docs (#22928)Angel Ezquerra2023-11-171-5/+5
| | | | | | | | | | | | This is a small improvement on top of PR #22924, which documents the new 'j' format specifier for Complex numbers. In addition to that it moves the handling of the j specifier into the function that actually implements it (formatValueAsComplexNumber), which seems a little cleaner. --------- Co-authored-by: Angel Ezquerra <angel_ezquerra@keysight.com> Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
* Add strformat support for Complex numbers (#22924)Angel Ezquerra2023-11-101-1/+36
| | | | | | | | | | | | | | | | | | | | | Before this change strformat used the generic formatValue function for Complex numbers. This meant that it was not possible to control the format of the real and imaginary components of the complex numbers. With this change this now works: ```nim import std/[complex, strformat] let c = complex(1.05000001, -2.000003) echo &"{c:g}" # You now get: (1.05, -2) # while before you'd get a ValueError exception (invalid type in format string for string, expected 's', but got g) ``` The only small drawback of this change is that I had to import complex from strformat. I hope that is not a problem. --------- Co-authored-by: Angel Ezquerra <angel_ezquerra@keysight.com>
* complete std prefixes for stdlib (#22887)ringabout2023-10-301-1/+1
| | | | follow up https://github.com/nim-lang/Nim/pull/22851 follow up https://github.com/nim-lang/Nim/pull/22873
* Simpler complex division implementation (#20088)Dan Rose2022-09-011-12/+1
|
* Implement complex sgn (#20087)Dan Rose2022-08-281-0/+7
| | | Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
* CIs: attempt to use csources_v1 (#16282)Andreas Rumpf2021-04-211-1/+1
| | | | | | | | * CIs: attempt to use csources_v1 * also updated the BSDs * also updated azure pipelines * std modules should not itself use the 'std/' import dir... * compiler has to be careful with std/ for v1 booting
* Improve documentation for complex (#16588)konsumlamm2021-01-051-101/+159
| | | | | | | | | | | | | * Improve documentation for complex Add missing doc comments * Add runnableExample Add links for principal values Optimize `-` Change var to let * Use std prefix for imports
* complex.nim: Use `func` everywhere (#16294)ee72020-12-091-60/+60
|
* complex minor improvement (#16086)flywind2020-11-211-129/+21
|
* [backport] fix #12528, fix #12525: incorrect generic type resolution for ↵Andreas Rumpf2019-10-281-0/+3
| | | | | | default values (#12538)
* [backport] run nimpretty on numbers stuffnarimiran2019-09-301-21/+21
|
* fixes #11834 (#12000)Palash Nigam2019-08-231-1/+1
|
* complex.nim: reformating [other]Andreas Rumpf2019-06-091-6/+2
|
* fix #9639 (#9640)Arne Döring2018-11-071-1/+1
|
* Generic Complex type (#9590)Arne Döring2018-11-051-317/+329
| | | | | | | | | | | | * remove `**` * const `im` can now be used with Complex64 * converters from float|int to Complex are replaced by procs * converters between various Complex types must stay to allow usage of `im` with Complex64 * limit types for `+`, `-`, `/`, and `*` between Complex and float * add `pow` for Complex and a number * complex type changes * unpublish approximation function
* Add imaginary unit. (#7922)Koki Fushimi2018-06-011-0/+4
|
* remove deprecated stuff from the stdlib; introduce better deprecation warningsAraq2018-05-051-2/+0
|
* lib: Trim .nim files trailing whitespaceAdam Strzelecki2015-09-041-4/+4
| | | | via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
* Fix buggy rect(), doc comment, and unit test.Charles Blake2015-02-281-3/+4
|
* Addition of some complex hyperbolic functionsJonathan Edwards2015-02-281-0/+70
|
* Extend complex to convert to/from polar coordinatesdef2015-02-161-2/+25
|
* Added complex conjugategmpreussner2015-01-241-27/+33
|
* fixes #495Araq2014-12-261-4/+1
|
* more modules updatedAraq2014-08-281-44/+44
|
* big renameAraq2014-08-271-2/+4
|
* Add missing complex arithmetic procsdef2014-07-141-0/+39
|
* Removes executable bit for text files.Grzegorz Adam Hankiewicz2013-03-161-0/+0
|
* additions to complex moduleAraq2011-01-071-6/+205
|
* bugfix: complex.nim compilesAndreas Rumpf2010-04-041-2/+2
|
* Bugfix: empty echo statementAndreas Rumpf2010-03-201-1/+1
|
* fixed pango/pangoutils new wrappersAndreas Rumpf2010-02-261-0/+0
|
* continued work on html/xmlparserrumpf_a@web.de2010-02-141-0/+0
|
* added tools and web dirsAndreas Rumpf2009-09-151-0/+0
|
* version0.7.10Andreas Rumpf2009-06-081-0/+106