Shop OBEX P1 Docs P2 Docs Learn Events
complex numbers on P2 ? — Parallax Forums

complex numbers on P2 ?

I would have liked to calculate with complex numbers on the P2.
riscvp2 has implemented <complex.h> and I've already done some experiments with it.
Unfortunately there is no full support for the P2 and I don't have the knowledge to expand this compiler.
With flexc and catalina I can't find any header files in the direction of <complex.h> either.
I have now started to calculate with double complex, whatever double means on the respective compiler.
I named the namespace _complex to avoid conflicts with a possible later version.
It is a kind of macro language, but I think it is quite comfortable.
I've made a few demos that compile with both flexspin and gcc on Linux.
The Demos:
RLC ... calculate the frequency response of a RLC Circuit and show it on an Osci.
unity_circle ... show the unity circle on Oszi in XY - mode.
genpi ... a demo that uses complex numbers, as opposed to the usual arithmetic with separate real and imaginary parts.
and my numeric_testbench for basic tests.
I will continue to expand the applications.
For example, I have an Inverse Laplace Transform in mind that already runs reasonably well on the PC.


  • Now I can present the Inverse Laplace Transform.
    As far as I know, the first ILT without a floating point unit.
    The step response of an RLC element can be seen on the osci.
    The Linux version is even more accurate, the P2 will overflow at higher iterations.
    With gcc you can compile without any changes in the code and see the exact result with gnuplot.
    You can also compile with riscvp2, but the program breaks off after a while.
    Maybe I should create the whole thing again with fixed point arithmetic.

Sign In or Register to comment.