The MASM Forum

Miscellaneous => Miscellaneous Projects => Topic started by: HSE on May 17, 2023, 02:32:50 AM

Title: Complex Numbers SmplMath backend
Post by: HSE on May 17, 2023, 02:32:50 AM
Hi all!

This is a new backend for SmplMath under development.

In essence is an adaptation of Complex Number Zlib Library (https://masm32.com/masmcode/rayfil/index.html) written by Raymond Filiatreault, previously translated to neutral bitness (Complex Numbers in 64 bits (http://masm32.com/board/index.php?topic=10269.msg112166#msg112166)).

Functions conserve capacity to read parameters from FPU and store results to FPU:
    fld problemx2.imag
    fld problemx2.real
    fld problemy.imag
    fld problemy.real
    invoke ZPower, SRC12_FPU or DEST_FPU or Z_DBL
    fstp solution.real
    fstp solution.imag

Capacity to read/store in adresses was replaced with and emulation of FPU stack (just like in double doule precision backend (http://masm32.com/board/index.php?topic=10750.0)):
    push_z problemx2
    push_z problemy
    invoke ZPower, Z_DBL
    pop_z solution

Of course, most interesting thing is an specific solve macro named fSlvZ:
.data
    problemx2  Z_NUM {-2.4 , 0.0}
    problemy    Z_NUM { 3.99, 0.0}
    solution    Z_NUM {          }

.code
    fSlvZ solution = problemx2 ^ problemy

And a little macro-parser allow to read complex numbers with some format (floating point format, parenthesis, sign between real and imaginary part, character i in imaginary part):
fSlvZ solution = (-2.4+0.0i)^(3.99+0.0i)

You can see that example is from Exponentiation (https://masm32.com/board/index.php?msg=111591) topic.

I will preciate some more complicated examples  :thumbsup:

I have to improve procedure that show complex numbers, and adapt example to 32 bits :biggrin:

Regards, HSE

Later: library 64 bits is builded with JWASM 15, and example with ML64.
                  SmplMathZ.zip (329.61 kB - downloaded 10 times.)

Later: library 32bits is builded with JWASM 15, and example with ML 14.

Title: Re: Complex Numbers SmplMath backend
Post by: HSE on May 19, 2023, 06:06:02 AM
A little better print:        Complex number functions library
   Written with MASM32 by Raymond Filiatreault
               February 15, 2005

(-2.4000e+000+0.0000e+000i) ^(3.9900e+000+0.0000e+000i)   =  (3.2872e+001-1.0330e+000i)

(-2.4000e+000+0.0000e+000i) ^(3.9900e+000+0.0000e+000i)   =  (3.2872e+001-1.0330e+000i)

(-2.4000e+000+0.0000e+000i) ^(3.9900e+000+0.0000e+000i)   =  (3.2872e+001-1.0330e+000i)

(-2.4+0.0i)^(3.99+0.0i)  =  (3.2872e+001-1.0330e+000i)

  Zneg (3.9900e+000+0.0000e+000i)   =  (-3.9900e+000-0.0000e+000i)

  Zneg (-2.4000e+000+0.0000e+000i)   =  (2.4000e+000-0.0000e+000i)

Press any key to continue...


Title: Re: Complex Numbers SmplMath backend
Post by: HSE on May 23, 2023, 11:27:43 PM
Now also with 32 bits example (using MASM32 SDK).

Updated in first post.