Hello all,
attached there's a "library" for newlisp to perform mathematical operations with complex numbers.
Such numbers are created with a list with the format : '(re im).
I added and tested all the included functions.
I also created a library for complex matrices determinant. The matrices needs to be written in columnmajor order.
I borrowed the permutation code from the newlisp web site and I added the function to calculate the parity of permutation.
Please feel free to test it and comment it.
This is my first newlisp program, and I'm sure there're a lot to improve.
Regards
complex arithmetics
complex arithmetics
 Attachments

 tcomplex.zip
 test file for both of them
 (377 Bytes) Downloaded 197 times

 perm.zip
 permutations library
 (1.14 KiB) Downloaded 200 times

 complex_lib.zip
 complex number library
 (966 Bytes) Downloaded 204 times
Re: complex arithmetics
There is a point to problem.
newlisp parser reads too long a numeric value (or symbol) without no warning.
Therefore, it is better to avoid such writing.
I recommend PI defined as:
P.S. I tried writing a mandelbrot set. like this http://www.newlisp.org/complex.cgi
Code: Select all
> (constant '*2pi* (mul 3.14159265358979323846264338327950288419716939937510 2))
3.159714599e+020
> (readexpr "(mul 3.14159265358979323846264338327950288419716939937510 2)")
(mul 3.141592653589793115997963468544185161590576171875 50288419716939937510L 2)
Therefore, it is better to avoid such writing.
I recommend PI defined as:
Code: Select all
(constant 'pi (mul 4 (atan 1))) ; or short written 3.141592654
Code: Select all
#!/usr/bin/env newlisp
(load "complex_lib.lsp")
(for (y 1 1.1 0.08)
(for (x 2 1 0.04)
(letn ((c 126)
(z (cmplx x y))
(a z))
(while (and (begin
(setq z (cadd (cmul z z) a))
(< (abs (cmod z)) 2))
(< 32 (dec c))))
(print (char c))))
(println))
(exit)
Re: complex arithmetics
Currently decimalpoint numbers are limited to 32 characters including the decimal point and sign. Which is about double the digits precision which internally can be distinguished in IEEE754 floating point numbers.
This character limit will be increased in the next version.
This character limit will be increased in the next version.